07-15-2014 09:44 AM
I have an xy graph with multiple points. The graph is controlled by a mouse down event, when the user clicks on the graph it draws a red circle at the click point. My question is how I would get this to snap to the nearest point?
Solved! Go to Solution.
07-15-2014 09:48 AM
07-15-2014 09:49 AM - edited 07-15-2014 09:50 AM
What is the datatype of the xy graph? If you use complex numbers (recommended!), convert the click point to a complex point in the data scale, subtract it from the complex array of points, take the absolute value, and use array min&max. The index of the min is the index of the closest point.
Can you attach your VI?
07-15-2014 09:51 AM
Please see my attached VI
07-15-2014 09:53 AM
That's just a subVI, there is no xy graph. Also your subVI is missing.
07-15-2014 09:55 AM
07-15-2014 09:59 AM - edited 07-15-2014 10:03 AM
Here's what I had in mind.
(just showing how to find the closest point. Now simply tranform the value back to pixel coordinates and draw the circle. Not shown.)
07-15-2014 10:10 AM
Sorry about that please see attached the updated VI
07-15-2014 10:23 AM
You shold be able to use my code with minimal changes. As I said, simply transform the position of the closest point back to pixels and draw the circle.
07-15-2014 10:34 AM
I have tried implementing your method but I am not having much luck?