Align left and right axes

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
neo
Newbie
Newbie
Posts: 7
Joined: Thu Jan 14, 2010 12:00 am

Align left and right axes

Post by neo » Thu Sep 16, 2010 9:12 pm

Hi,

I'm trying to align the left and right axes. I want the grid lines to nicely overlap even though the scales are different. The chart is created at runtime and is only ever drawn onto a bitmap.

Thanks,
neo

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

Re: Align left and right axes

Post by Narcís » Fri Sep 17, 2010 7:23 am

Hi neo,

In that case you could do as discussed in this thread. This is a TeeChart for .NET thread but same principles apply to TeeChart VCL.
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

neo
Newbie
Newbie
Posts: 7
Joined: Thu Jan 14, 2010 12:00 am

Re: Align left and right axes

Post by neo » Fri Sep 17, 2010 6:11 pm

Thanks Narcis.

I've read through the thread and tried to get it working but I haven't had any luck. I'm not sure this thread gives me exactly what I'm looking for. My left and right axis differ in scale and units. The left axis also contains a number of lines (i.e. line series) whereas the right axis only contains 1 line.

For example consider the following:

Left axis is in 'meters' and has 10 lines. Each line has a different y value for a given x value but all y values for all lines fall in between 0 and 20 meters.
Right axis is in 'seconds' and there is only one. This line have y values between 200 and 10000 seconds.

How can I configure the chart to have the grid lines synchronize with each other? I can't call SetMinMax with the same values for each axis because they are completely different units.

I was also wondering if you could help me convert the following (from the thread) into pascal:

Code: Select all

            tChart1.Axes.Right.StartEndPositionUnits = Steema.TeeChart.PositionUnits.Pixels;
Thanks

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

Re: Align left and right axes

Post by Yeray » Mon Sep 20, 2010 8:11 am

Hi neo,

Here it is a simple example trying to simulate the situation you described. I've achieved the synchronized axes labels with custom labels in the right axis:

Code: Select all

uses series;

procedure TForm1.FormCreate(Sender: TObject);
var i, n: Integer;
begin
  Chart1.View3D:=false;

  for n:=0 to 1 do
    with Chart1.AddSeries(TFastLineSeries) do
      for i:=0 to 14 do
        Add(Random*20);

  with Chart1.AddSeries(TFastLineSeries) do
  begin
    VertAxis:=aRightAxis;
    for i:=0 to 14 do
      Add(200+Random*9800);
  end;

  Chart1.Draw;
  ReCalcRightLabels;
end;

procedure TForm1.ReCalcRightLabels;
var i: Integer;
    tmp: double;
begin
  Chart1.Axes.Right.Items.Clear;
  with Chart1.Axes.Left do
    for i:=0 to Items.Count-1 do
    begin
      tmp:=Chart1.Axes.Right.CalcPosPoint(CalcPosValue(Items[i].Value));
      Chart1.Axes.Right.Items.Add(tmp, FormatFloat('#.##', tmp));
    end;
end;
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

neo
Newbie
Newbie
Posts: 7
Joined: Thu Jan 14, 2010 12:00 am

Re: Align left and right axes

Post by neo » Mon Sep 20, 2010 8:22 pm

Hi Yeray,

Thanks for your suggestion. I'm sure this would work fine if my TChart's parent was a TForm. I guess the biggest problem is that my TChart does *not* have a parent that is utimately a TForm. This thread seems to discuss the problem I am having:

http://www.teechart.net/support/viewtop ... ndow#p3185

Unfortunately the aforementioned thread suggests modifying the TChart source that I don't have. If I try to manually draw a TChart (i.e myChart.Draw) I receive an EInvalidOperation with message 'Control " has no parent window'.

I'd prefer to leave my TChart "Form-less" as I only need to draw it directly to a bitmap. Does anyone have any suggestions?

Thanks,
neo

neo
Newbie
Newbie
Posts: 7
Joined: Thu Jan 14, 2010 12:00 am

Re: Align left and right axes

Post by neo » Tue Sep 21, 2010 6:11 pm

Hi,

I resolved the issue by creating an invisible TForm and drawing the TChart on that.

Thanks for everyones help.

Cheers

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

Re: Align left and right axes

Post by Yeray » Wed Sep 22, 2010 7:25 am

Hi neo,

Thanks for sharing your solution!
I glad to hear you found it.
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