Recent

Author Topic: How to get X and Y Values continuosly using OnMouseMove?  (Read 1867 times)

bvn123

  • New Member
  • *
  • Posts: 17
How to get X and Y Values continuosly using OnMouseMove?
« on: November 08, 2020, 08:35:23 pm »
Good evening,
Is there simple mean to get an Index for Series' X,Y Values using X parameter of OnMouseMove event or using approximate XValue to be calculated on OnMouseMove(X)?
The aim is to show continuous change of common X and a few Y Values for some number of series when mouse is moving over a chart.
I already saw the answers here where TChartToolset, TUserDefinedChartSource are used.
It seems for me to calculate a range for X values and scale it using chart.width and image position or to find the nearest XValue in XValues list is simlier.
But may be I didn't find an appropriate function for getting Index?
Thanks.

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: How to get X and Y Values continuosly using OnMouseMove?
« Reply #1 on: November 08, 2020, 11:23:24 pm »
I do not fully understand what you want to achieve. But I am attaching a little demo project which shows how to use the TDataPointCrosshairTool - it draws a cursor underneath the mouse which locks to the data points. There are other, similar tools which popup a hint window for the data point underneath the mouse (TDatapointHintTool), which respond to clicks on data points (TDataPointClickTool), or with which you can drag data points (TDatapointDragTool)

bvn123

  • New Member
  • *
  • Posts: 17
Re: How to get X and Y Values continuosly using OnMouseMove?
« Reply #2 on: November 09, 2020, 09:00:03 am »
wp, thank You for answer,

I had read Your answers for the similar questions before posting this one.

I placed here
http://accelerometer.narod.ru/Time_XYZ_OnMouseMove.mkv
a video of my delphi app which shows a current time (Bottom Axis) and 3 coordinats X,Y,X to be corresponding to current time when mouse is moving over a chart.
As in Delphi so as in Lazarus, I may get the corresponding Values: TimePoint and 3 parameters of my device for this TimePoint using the arrays:
seriesTime.Values[Index] (bottom axis),
seriesX.Values[Index], seriesY.Values[Index], seriesZ.Values[Index] (left axis).
But I can't find, how to calculate the Index for mouse position on the Chart.
Has the TAChart some simple functions to get this <Index> to be calculated using event's OnMouseMove parameters X,Y?
I saw your examples where You show how to get x,y in Chart coords for mouse position.
To catch nearest point for only one series on a time as in Your example - this is another desicion, but ...

Best regards.

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: How to get X and Y Values continuosly using OnMouseMove?
« Reply #3 on: November 09, 2020, 10:48:16 am »
In fact, you can achieve this with the ChartTools, but I want to answer your specific question:

Use the series method GetNearestPoint to determine the nearest data point to a given mouse position. Since the result depends on several parameters you must fill in a TNearestPointParams record and get the results in a TNearestPointResults record. TNearestPointParams contains the mouse point (FPoint), the distance measuring function (FDistFunc), the tolerance (FRadius) and a specification which part of the data point structure should be checked (FTarget). The distance measuring function here should evaluate only the x coordinates, an implementation is the function PointDist() in unit TAGeometry. The NearestPointResults contain the current distance (FDist), the data point index (FIndex) and the series point in pixels (FImg) and graph coordinates (FValue).

bvn123

  • New Member
  • *
  • Posts: 17
Re: How to get X and Y Values continuosly using OnMouseMove?
« Reply #4 on: November 09, 2020, 04:10:31 pm »
wp,

thank You very much,
this is what i wanted and is simple enough in use.

Best regards.

bvn123

  • New Member
  • *
  • Posts: 17
Re: How to get X and Y Values continuosly using OnMouseMove?
« Reply #5 on: November 09, 2020, 04:28:25 pm »
wp,

Your examples I tested from Lazarus for Windows.
Would Your desicions published above for TAChart fully work for Lazarus Linux
or some peculiarities for TAChart in Lazarus Linux may appear?
« Last Edit: November 09, 2020, 04:32:44 pm by bvn123 »

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: How to get X and Y Values continuosly using OnMouseMove?
« Reply #6 on: November 09, 2020, 04:36:32 pm »
No, TAChart is cross-platform, I compiled and ran several TAChart programs on other widgetsets and did not see issues (with the exception of cocoa/macOS, maybe).

bvn123

  • New Member
  • *
  • Posts: 17
Re: How to get X and Y Values continuosly using OnMouseMove?
« Reply #7 on: November 09, 2020, 05:09:03 pm »
great,
thanks once more.

 

TinyPortal © 2005-2018