Page 1 of 1

Align left and right axes

Posted: Thu Sep 16, 2010 9:12 pm
by 10055061
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

Re: Align left and right axes

Posted: Fri Sep 17, 2010 7:23 am
by narcis
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.

Re: Align left and right axes

Posted: Fri Sep 17, 2010 6:11 pm
by 10055061
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

Re: Align left and right axes

Posted: Mon Sep 20, 2010 8:11 am
by yeray
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;

Re: Align left and right axes

Posted: Mon Sep 20, 2010 8:22 pm
by 10055061
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

Re: Align left and right axes

Posted: Tue Sep 21, 2010 6:11 pm
by 10055061
Hi,

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

Thanks for everyones help.

Cheers

Re: Align left and right axes

Posted: Wed Sep 22, 2010 7:25 am
by yeray
Hi neo,

Thanks for sharing your solution!
I glad to hear you found it.