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
How to align two charts
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
In the following example, we made two series in two different charts, we set different legend widthes and aligned them.
I hope it helps.
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;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |