Forum > TAChart
Reading axis range after auto-scale
(1/1)
thbu:
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:
Try: ..Series.GetMax
wp:
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 [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses TAChartUtils; procedure GetAxisRange(Axis: TChartAxis; var AMin, AMax: Double);var t: TAxisTransform; at: TChartAxisTransformations; ext: TDoubleRect; chart: TChart;begin chart := Axis.Arrow.GetOwner as TChart; at := Axis.GetTransform; for t in at.List do if t is TAutoscaleAxisTransform then begin AMin := at.GraphToAxis(TAutoscaleAxisTransform(t).MinValue); AMax := at.GraphToAxis(TAutoscaleAxisTransform(t).MaxValue); exit; end; // No autoscale transform available ext := chart.LogicalExtent; if Axis.IsVertical then begin AMin := at.GraphToAxis(ext.a.Y); AMax := at.GraphToAxis(ext.b.Y); end else begin AMin := at.GraphToAxis(ext.a.X); AMax := at.GraphToAxis(ext.b.X); end;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:
Thank you. It works very well.
Navigation
[0] Message Index