Aligning 2 charts' Y axis

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
RSpence
Newbie
Newbie
Posts: 33
Joined: Fri Apr 02, 2004 5:00 am
Location: UK / Florida
Contact:

Aligning 2 charts' Y axis

Post by RSpence » Mon Apr 11, 2005 11:31 pm

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

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

Post by Narcís » Tue Apr 12, 2005 8:19 am

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;
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

RSpence
Newbie
Newbie
Posts: 33
Joined: Fri Apr 02, 2004 5:00 am
Location: UK / Florida
Contact:

Post by RSpence » Tue Apr 12, 2005 5:01 pm

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.

Post Reply