Hi,
Here's another one. I have two charts on a form. I need to have their Y axis aligned exactly. The problem is the captions on the Y AXIS are different widths - typically the top charts values are in the 1000s and the bottom ones are single digits. The widths of the labels seems to be throwing off the positions of the Y Axis. Following code illustrates this (3D set false at design time).
chrtTop: TChart;
chrtBott: TChart;
SeriesTop: TBarSeries;
SeriesBott: TBarSeries;
// ....
self.chrtTop.Left := 0;
self.chrtTop.Width := 300;
self.chrtTop.Height := self.Height div 2;
self.SeriesTop.AddXY(1, 10000);
self.chrtBott.left := 0;
self.chrtBott.Top := (self.Height div 2) + 1;
self.chrtBott.Width := 300;
self.chrtBott.Height := self.Height div 2;
self.SeriesBott.AddXY(1, 1);
self.chrtBott.LeftAxis.LabelsSize :=
self.chrtTop.LeftAxis.LabelWidth(self.SeriesTop.MaxYValue );
Setting the bottom chart's leftAxis.LabelsSize helps, but it's still off by a few pixels. Is there something else I need to take into account?
Sample project available,
Thnks,
Rick
Aligning 2 charts' Y axis
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi Rick,
Setting charts margins may help you. You can set them either at design-time or run-time using:
Setting charts margins may help you. You can set them either at design-time or run-time using:
Code: Select all
Chart1.MarginUnits:=muPixels; //default muPercent;
Chart1.MarginLeft:=10;
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 |
Hi Narcis,
Thanks for the tip - but the values for marginLeft were already the same for both charts. The solution I came up with was:
i := self.framSampStatsGraphs.chrtFrequency.LeftAxis.PosAxis -
self.framSampStatsGraphs.chrtBoxPlot.LeftAxis.PosAxis;
self.framSampStatsGraphs.chrtBoxPlot.Left := self.framSampStatsGraphs.chrtFrequency.Left + i;
self.framSampStatsGraphs.chrtBoxPlot.Width := self.framSampStatsGraphs.chrtFrequency.Width - i;
i.e. I calculate the diffrence between the values of the 2 charts' LeftAxisPosAxis propertiesthen move the bottom chart by that value.
Thanks for the tip - but the values for marginLeft were already the same for both charts. The solution I came up with was:
i := self.framSampStatsGraphs.chrtFrequency.LeftAxis.PosAxis -
self.framSampStatsGraphs.chrtBoxPlot.LeftAxis.PosAxis;
self.framSampStatsGraphs.chrtBoxPlot.Left := self.framSampStatsGraphs.chrtFrequency.Left + i;
self.framSampStatsGraphs.chrtBoxPlot.Width := self.framSampStatsGraphs.chrtFrequency.Width - i;
i.e. I calculate the diffrence between the values of the 2 charts' LeftAxisPosAxis propertiesthen move the bottom chart by that value.