02-17-2021 11:52 AM
I would like to move the cursor of a xy graph using a mouse move event. The cursor should be snapped to the plot the whole time.
I've tried translating the current mouse postion into the XY coordinates of the graph using "Map Coords To XY",
which seems to work, because the cursor takes the correct X-coordinate.
For some strange reason though, the Y-coordinate has a value of the following data point and not the current one.
I've attached the VI for reference.
Does anyone know what's going wrong and how I can fix it?
02-17-2021 12:53 PM - edited 02-17-2021 01:16 PM
Your cursor snaps to the plot, so don't move it around programmatically. You also have a race condition that you read the cursor list before the code updates the value.
All you need is use the "cursor index" property to find the point where the cursor is locked. Make the event "cursor move". Virtually no code needed.
(Since your x-values are spaced equally, I am not sure why you are even using an xy graph.)
02-17-2021 01:22 PM
Thank you for your answer.
I need the cursor to follow my mouse automatically. Without the "Mouse Move" event, I would have to actually click on the cursor and drag it to the place where I want it to be. What I rather want is, that the cursor is following the mouse (without the need to click or drag anything) and snaps to the closest point available.
02-17-2021 01:27 PM - edited 02-17-2021 01:36 PM
OK, here's a solution using the mouse move event. You can modify it so it only uses x distance.
02-17-2021 01:38 PM - edited 02-17-2021 01:42 PM
If you want to use the xy distance, you need to decide if the distance should be in graph units or pixel units.
Here's an example for truly random xy data: