Recent

Author Topic: Controlling Extent with two Y-axes  (Read 2363 times)

mtanner

  • Sr. Member
  • ****
  • Posts: 287
Controlling Extent with two Y-axes
« on: January 24, 2017, 01:33:42 pm »
In a chart with just a single Y axis, I can control the extent to be displayed like this:

With MyChart.Extent do begin
     XMin:=<user x min value>;  UseXMin:=true/false for auto or non-auto;
     XMax:=<user x max value>;  UseXMax:=true/false for auto or non-auto;
     YMin:=<user y min value>;  UseYMin:=true/false for auto or non-auto;
     YMax:=<user y max value>;  UseYMax:=true/false for auto or non-auto;
end;

Hope my pseudo-code is intelligible. This works fine as a general method for me.

How do I control extents when I have two separate y axes?

ording auto =I have a striaghtforward chart jsing two y axes./

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Controlling Extent with two Y-axes
« Reply #1 on: January 24, 2017, 04:23:52 pm »
Several coordinate systems are needed when TAChart creates diagrams with two y axes. At first there is the coordinate system of the numbers to be plotted - TAChart calls this "axis" units because these are the number painted along the axes. In case of two y axes, both quantities have different units. In order to plot them within the same screen rectangle the y values must be transformed to a common coordinate system with is drawn onto the chart. This is called "graph" units. If you remember previous threads, this transformation is executed by means of the AutoscaleTransforms assigned to each y axis.

The Chart.Extent that you refer to is given in Graph units, because the chart does not "care" about the transformations - they are the matter of the axes. If you control the range of an axis by means of the Chart.Extent then this works only if there is no transformation because graph and axis units are equal in this case.

If axes are transformed you can control the axis range by means of the Range property of the axis. It is similar to the Chart.Extent, except that it has only one dimension (Min, Max, UseMin, UseMax)  - and that it is given in axis units because the axis DOES know about the transformation.

Therefore, the only thing you must do is to set the Min/Max of the axis.Range to the required values and set the corresponding UseXXXX parameters to true. Please note that when setting Min/Max you must be sure that Max is always greater than the current Min.

Have a look at the attached demo. It has two y axes and a SpinEdit for the Max/Min value of each y axis. Using these edit controls you can change the range of each y axis independently.

 

TinyPortal © 2005-2018