Recent

Author Topic: Reading axis range after auto-scale  (Read 255 times)

thbu

  • Newbie
  • Posts: 6
Reading axis range after auto-scale
« on: April 23, 2025, 09:11:32 am »
Hi,

I'm using TChart with multiple Y-axis and TAutoScaleAxisTransform for auto-scale. How can I find out the minimum and maximum value of each axis that after auto-scaling is done?
To clarify, I do not mean an event that is executed after autoscaling, but simply a way to read the auto-scaled min/max of each axis.

arneolav

  • Full Member
  • ***
  • Posts: 197
Re: Reading axis range after auto-scale
« Reply #1 on: April 23, 2025, 09:51:31 am »
Try: ..Series.GetMax
Win 11, win64 , Lazarus 4.0RC3
Delphi/DevExpress

wp

  • Hero Member
  • *****
  • Posts: 12761
Re: Reading axis range after auto-scale
« Reply #2 on: April 23, 2025, 11:41:42 am »
You probably mean the range in axis units (i.e. units of the user data)? In graph units, with autoscale transformation, the axis values range between the MinValue and MaxValue specified by the AutoScaleAxisTransform. In order to get them in in axis units, you have to apply the method GraphToAxis of the axistransformation which, in turn, you get from the method GetTranform of the axis.

The following procedure is rather general, it also handles the case that no autoscale transformation is used:

Code: Pascal  [Select][+][-]
  1. uses
  2.   TAChartUtils;
  3.  
  4. procedure GetAxisRange(Axis: TChartAxis; var AMin, AMax: Double);
  5. var
  6.   t: TAxisTransform;
  7.   at: TChartAxisTransformations;
  8.   ext: TDoubleRect;
  9.   chart: TChart;
  10. begin
  11.   chart := Axis.Arrow.GetOwner as TChart;
  12.   at := Axis.GetTransform;
  13.  
  14.   for t in at.List do
  15.     if t is TAutoscaleAxisTransform then
  16.     begin
  17.       AMin := at.GraphToAxis(TAutoscaleAxisTransform(t).MinValue);
  18.       AMax := at.GraphToAxis(TAutoscaleAxisTransform(t).MaxValue);
  19.       exit;
  20.     end;
  21.  
  22.   // No autoscale transform available
  23.   ext := chart.LogicalExtent;
  24.   if Axis.IsVertical then
  25.   begin
  26.     AMin := at.GraphToAxis(ext.a.Y);
  27.     AMax := at.GraphToAxis(ext.b.Y);
  28.   end else
  29.   begin
  30.     AMin := at.GraphToAxis(ext.a.X);
  31.     AMax := at.GraphToAxis(ext.b.X);
  32.   end;
  33. end;  

I added this to the Chart Runtime FAQ wiki: https://wiki.freepascal.org/TAChart_Runtime_FAQ#How_to_find_the_range_of_values_covered_by_an_axis

thbu

  • Newbie
  • Posts: 6
Re: Reading axis range after auto-scale
« Reply #3 on: April 24, 2025, 02:43:43 pm »
Thank you. It works very well.

 

TinyPortal © 2005-2018