Page 1 of 1

Aligning 2 charts' Y axis

Posted: Mon Apr 11, 2005 11:31 pm
by 9336985
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

Posted: Tue Apr 12, 2005 8:19 am
by narcis
Hi Rick,

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;

Posted: Tue Apr 12, 2005 5:01 pm
by 9336985
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.