Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2014-09

TAChart DataPointCrossHairTool

5 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Leonardo M. Ramé

Hi, I'm playing with the DataPointCrossHairTool, and I would like to know if it's possible to display the horizontal line on cursor's position, instead as the default data point value.

If mean, for example, my points are:

1: 10
2: 20
3: 30

When the mouse cursor is between 20 and 10, say 13 for example, the default behavior is displaying a line at 10 or 20, but what if I want to display the line just at 13?.

Regards,

Reply by email

Werner Pamler
> Hi, I'm playing with the DataPointCrossHairTool, and I would like to > know if it's possible to display the horizontal line on cursor's > position, instead as the default data point value.

Not 100% sure, but I believe that this tool always snaps to the data points. An alternative would be to add a constant line series to the chart and use a TDatapointDragTool to drag the line. Use the chart's MouseDown to show and the MouseUp to hide the line. The "toolsdemo" in TAChart's demo folder is an example of the basic idea (the green and purple dashed vertical lines).

Reply by email

Leonardo M. Ramé
to Werner Pamler
Werner Pamler wrote 15 lines
>> Hi, I'm playing with the DataPointCrossHairTool, and I would like to >> know if it's possible to display the horizontal line on cursor's >> position, instead as the default data point value. Not 100% sure, but I believe that this tool always snaps to the data points. An alternative would be to add a constant line series to the chart and use a TDatapointDragTool to drag the line. Use the chart's MouseDown to show and the MouseUp to hide the line. The "toolsdemo" in TAChart's demo folder is an example of the basic idea (the green and purple dashed vertical lines). --

I kind of got what I need, based on Mouse.CursorPos and TAChart.ScreenToClient.

Now, I need to convert the mouse pos to a relative value to the axis.

In the AfterDrawBackWall event, to get current Y cursos position, I have:

ASender.ScreenToClient(Mouse.CursorPos).Y

Now, how can I convert that value to its relative to axis value.

Please, take a look at the attached screenshot, in the bottom chart, you can see the cursor and an horizontal line, with its value at the rigth axis, in this case is a 64 (yellow bold) between 3.50 and 4.00, instead of 64 I want to display the correct value (approx. 3.95).

Leonardo M. Ram? http://leonardorame.blogspot.com -------------- next part -------------- A non-text attachment was scrubbed... Name: Screenshot - 210914 - 13:41:22.png Type: image/png Size: 30629 bytes Desc: not available URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140921/8f6a6910/attachment-0001.png>

Reply by email

Werner Pamler

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.

Reply by email

Leonardo M. Ramé
to Werner Pamler
Werner Pamler wrote 28 lines
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.

Great!, here's a screenshot.

Meanwhile I found a way to get the Y pixel value of a point, as you can see, the "19.60" with yellow background refers to the last point in my series, and is drawn exactly at the same position of the Close Y Point. For this I used GetYImgValue( Index of last point ) of the series.

Leonardo M. Ram? http://leonardorame.blogspot.com -------------- next part -------------- A non-text attachment was scrubbed... Name: Screenshot - 210914 - 18:15:42.png Type: image/png Size: 29681 bytes Desc: not available URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140921/dfc2db8f/attachment-0001.png>

Reply by email