Recent

Author Topic: Left axis linear, right axis log?  (Read 2424 times)

piola

  • Full Member
  • ***
  • Posts: 124
  • Lazarus 2.2, 64bit on Windows 8.1 x64
Left axis linear, right axis log?
« on: February 09, 2019, 08:35:19 pm »
Hello,

I hope there's someone that can help me with a TAChart problem. I already spent hours of googling and trying, but I am still not knowing what I'm doing wrong.

I want to display two series in a chart with independent left and right y axis. Both series share the same x-data. Series1 should be assigned the left axis with linear scale. Series2 should be assigned the right axis with log scale.

This is my result (see attached screenshot):

- Left one: no TAutoScaleAxisTransform at all, this is what I expected.
- #2: Left and right axis = TAutoScaleAxisTransform; right axis = TAutoScaleAxisTransform assigned first, then TLogarithmAxisTransform
- #3: Left and right axis = TAutoScaleAxisTransform; right axis = TLogarithmAxisTransform first, then TAutoScaleAxisTransform
- #4: same as #2, but all axis ranges fixed to 1..100

None of the results is not even close to what I want to achieve, and I don't know why. Solutions 2 and 4 are ok regarding the log-scale, but whatever I do, the 2nd series is "stacked" on top of the 1st, even if I set the AutoScale ranges to 0..1 for both axes.

Number 3 is ok regarding the positioning and scaling of the series, but the logarithm gets lost.

I have found absolutely no hint what to take into account when combining two axis transformations, so any help is appreciated. Thank you very much!

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: Left axis linear, right axis log?
« Reply #1 on: February 09, 2019, 10:19:11 pm »
When multi-axes charts do not work for me I usually have forgotten to assign the axis indexes to the series, or to assign the transformations to the axes.

The basic principles:
  • Add a ChartTransformations component for each axis which is to be transformed
  • Add a TAutoScaleTransformation for the left axis
  • Add a LogarithmicTransform and an AutoscaleTransform for the right axis. The order is important: Log first then AutoScale because the logarithms have to be calculated first, the result of the first transformation will be subject to the AutoScaleTransform.
  • Assign each ChartTransformations component to the Transformations property of the corresponding axis.
  • Set the AxisIndexX and AxisIndexY of each series to the index of the axes on which it will be plotted. Assuming the standard order of the axes, the series for the left axis must have AxisIndexX=1 (bottom axis) and AxisIndexY=0 (left axis), the series for the right axis must have AxisIndexX=1 and AxisIndexY=2.
  • If you want both series to cover the full scale of the chart keep the MinValue and MaxValue of each AutoScaleTransform. Otherwise you can adjust the space for each axis with these parameters.

If you need a practical example look at the attached demo.

piola

  • Full Member
  • ***
  • Posts: 124
  • Lazarus 2.2, 64bit on Windows 8.1 x64
Re: Left axis linear, right axis log?
« Reply #2 on: February 09, 2019, 11:55:24 pm »
Thank you very much, everything is ok now. I indeed had one wrong assignment (I have to create everything at runtime).

 

TinyPortal © 2005-2018