Forum > TAChart
mouse cursor depiction on line graph
(1/1)
Firebird:
Dear all,
Is there a function available from the graph function library for selecting the cursor image on the x-y graph differently from the outside axis definition part of the graph for a line graph (see images 1 and 2)? Thanks for your feedback in advance.
wp:
Write a handler for the chart's OnMouseMove event with the following code:
--- 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, TAMath; function PointInRect(P: TDoublePoint; R: TDoubleRect): Boolean;begin Result := InRangeWithLimits(P.X, R.A.X, R.B.X) and InRangeWithLimits(P.Y, R.A.Y, R.B.Y);end; procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);var P: TDoublePoint; ext: TDoubleRect;begin ext := Chart1.CurrentExtent; P := Chart1.ImageToGraph(Point(X, Y)); if PointInRect(P, ext) then Screen.Cursor := crHandPoint else Screen.Cursor := crDefault;end;
Chart1.CurrentExtent is the rectangle (in "real-world"-coordinates) spanned by the axes (well... not always). Chart1.ImageToGraph converts the mouse coordinates to "real-world" coordinates. Finally there is a custom-written function PointInRect which checks whether this transformed mouse point is inside the axis rectangle.
BTW, the cross cursor in your screenshot is not a standard cursor coming with the LCL. If you have it as a CUR file you can link it as a resource and load it from there which gives you the number which you can assign to Screen.Cursor (rather than crHandPoint in my sample code).
Firebird:
Thank you wp that really helps, in particular with the zooming function - drawing a rectangle to zoom into close to the graph borders! I am using an older version of Lazarus - the Cross cursor is part of that version, there is no problem with that.
Navigation
[0] Message Index