LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Graph cursor does not snap to the correct coordinate

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?

 

 

 

 

 

0 Kudos
Message 1 of 5
(1,416 Views)

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.)

 

altenbach_0-1613587964111.png

 

0 Kudos
Message 2 of 5
(1,384 Views)

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.

0 Kudos
Message 3 of 5
(1,367 Views)

OK, here's a solution using the mouse move event. You can modify it so it only uses x distance.

 

altenbach_0-1613590033081.png

 

0 Kudos
Message 4 of 5
(1,364 Views)

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:

 

altenbach_0-1613590928281.png

 

 

 

0 Kudos
Message 5 of 5
(1,356 Views)