How to align two charts

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
efa
Newbie
Newbie
Posts: 3
Joined: Wed Feb 28, 2007 12:00 am

How to align two charts

Post by efa » Thu Mar 01, 2007 2:56 pm

Hello!

On my form I have 2 TCharts. I need to display the two charts directly beneath each other so that the two left axes are perfectly aligned and the ChartWidth of the two charts is exactely the same.

Is this possible?

Regards,
Erik

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Mar 01, 2007 3:09 pm

Hi Erik,

Yes, this is possible. You can try doing something as told here.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

efa
Newbie
Newbie
Posts: 3
Joined: Wed Feb 28, 2007 12:00 am

Post by efa » Thu Mar 01, 2007 3:25 pm

Hi!

I did try that but unfortunately it will not work because the legends of the two charts has different sizes. How can I compensate for this?

Regards,
Erik

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Post by Yeray » Fri Mar 02, 2007 11:18 am

In the following example, we made two series in two different charts, we set different legend widthes and aligned them.

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
  Series1.FillSampleValues(100);
  Series2.FillSampleValues(200);

  //Creating diferent size titles for each legend
  Chart1.Legend.Title.Text.Clear;
  Chart1.Legend.Title.Text.Add('Chart1 Title xxxxxxxxxxxx');

  Chart2.Legend.Title.Text.Clear;
  Chart2.Legend.Title.Text.Add('Chart2 Title');

  LeftAlignCharts([Chart1,Chart2],100,600);

  Chart1.Draw;
  Chart2.Draw;
  RightAlignCharts
end;

//this is the method to resize the charts that Narcis suggested to you before
procedure TForm1.LeftAlignCharts(Const Charts: Array of TCustomChart; aLeft: Integer; aWidth: Integer);
var i: Integer;
begin

  for i := Low(Charts) to High(Charts) do
  // Left align charts
  With Charts[i] do
  begin
    Left := aLeft;
    Width := aWidth;
    MarginLeft := 0;
    Axes.Left.TitleSize := 15;
    Axes.Left.LabelsSize := 30;
    Axes.Left.LabelsAlign := alDefault;
  end;
end;

//This is to resize the chart which has a smaller legend.width
procedure TForm1.RightAlignCharts;
begin
     if Chart1.Legend.Width > Chart2.Legend.Width then
     begin
          Chart1.Legend.HorizMargin:=10;
          Chart2.Legend.HorizMargin := Chart1.Legend.Width - chart2.Legend.Width + Chart1.Legend.HorizMargin;
     end
     else
         begin
              Chart2.Legend.HorizMargin:=10;
              Chart1.Legend.HorizMargin := Chart2.Legend.Width - chart1.Legend.Width + Chart2.Legend.HorizMargin;
         end;
end;
I hope it helps.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply