LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do you map a mouse events coordinates to the coordinates of a chart or graph?

I'm using LabView 6.1 on Win XP Pro. I'm trying to highlight points on a graph picked (by using a mouse click) by a user. The mouse click event returns x,y in pixels relative to the upper left corner. I know the upper left corner of my control. I also know the width and height of the plotting area within the control, but I don't know the position of the plotting area within the control. Without that piece of info, I can't do the mapping.
0 Kudos
Message 1 of 5
(4,104 Views)
Hi,

You May Want to do this a bit Differently but achieve the same Goal i.e. the user Picks Points on a Graph and you highlight these points and Draw A graph or impart some other functionality.

Here is an idea -

1. Let the User Position the Cursor on the Point they want. To aid the user you can make the cursor legend visible which shows the X and Y Axis values for the cursor. To accuartely Position the User can use the the 4 Buttons that are a part of the Cursor Legend.

2. Put a Button next to the graph saying "Select this Point"

3. After Positioning the Cursor when the user Clicks this Button you use the "Cursor Position" Property of the graph to extract the value of the cursor.

4. Next you may want to add this Point to Cluster Array which displays
the Points on the Graph. If this Array is Empty and you add this one Element to the Graph then this Point will be Visible. The User may now reposition to another Point and Repeat the Process.

5. To aid the user you may want to Provide " Delete last Point" and "Clear All" Buttons. The Functionality is to Delete Last Element in array or Clear all Elements in the Array.

The Structure of this whole routine probably is Event Structure(to trap Button Clicks "Select", "Delete" etc) Inside a Case Structure (State Machine to Perform the Operations User Clicked) All Inside a While Loop.

This is a Short Description of how this Functionality can be Built. To Automatically Extract Cursor position from the Graph and then try to Map it to Coordiante Axis For a Point is More Involved and a Little Convoluted.

Why not keep it simple? IF anything is unclear, I will be glad to explain or post an example (Only if time permits!!)

Good Luck

Mache
Good Luck!

Mache
0 Kudos
Message 2 of 5
(4,104 Views)
Hello,

I agree, using the cursor functionality in some respect is a great idea. You could even have the user place a cursor, make it snap to the graph, and make the cursor invisible and just programmatically change the properties of that point on the graph. This would create the illusion of highlighting a point on the graph nearest to where the user clicked.

Mache's suggestions will work for implementing a structure similar to this. Let us know if there is anything else we can do to help. Have a great week!

Liz Fausak
Applications Engineer
National Instruments
www.ni.com/support
0 Kudos
Message 3 of 5
(4,104 Views)
Thanks, Mache. But what you've described is pretty much what I've already got. I was hoping to simplify the process by eliminating the drag cursor/add point and simply have the user click inside the plot area to add a point (left-click add, right-click remove).
0 Kudos
Message 4 of 5
(4,104 Views)
I solved this problem by overlapping a transparent picture control with the plotting area of my graph. Since the border of the picture control is fixed in size (i.e. 3 pixels wide), I can use the top/left coordinates of the picture control to determine where within the picture (and underlying plot) the user has clicked and then map the pixel coordinates to plot coordinates. It should've been easier than this though. I've attached my solution.
0 Kudos
Message 5 of 5
(4,104 Views)