[Lazarus] TAChart DataPointCrossHairTool
Werner Pamler
werner.pamler at freenet.de
Sun Sep 21 21:54:39 CEST 2014
To convert image coordinates (pixels within the chart rectangle which
you, indeed, can obtain from the global mouse position converted to the
local chart pixels) to "graph" coordinates you call the chart methods
* "XImageToGraph(x:Integer): Double" for x coordinates,
* "YImageToGraph(y:Integer): Double" for y coordinates, or
* "ImageToGraph(P:TPoint): TDoublePoint" (for both).
(or XGraphToImage() etc for the other direction).
If you do not use axis transformations, then graph coordinates directly
refer to the units of your data. If, on the other hand, axis
transformations are involved (logarithmic axes, multiple axes etc) the
values on the axes may be different from the graph units used in an
internal coordinate system. In this case, you have to link the series to
the axis (by means of the AxisIndexX and AxisIndexY properties) and call
the GraphToAxis or AxisToGraph methods of the AxisTransformation which
is obtained from the method GetTransform of the axis. In your example of
y values the transformation chain would be
mouse point yi --> graph coords by yg := Chart.YImageToGraph(yi) -->
axis coords by ya := Chart.LeftAxis.GetTransform.GraphToAxis(yg).
Here, ya refers to your input data, yi to the pixel data.
But since you don't use transformations YImageToGraph is sufficient.
More information about the Lazarus
mailing list