Example Code

Get plot name and x/y values at mouse position

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

 

Overview
This example shows how you can obtain the name of a plot and x/y values by mouse over. It further shows how to display the information in the plot at mouse position.


Description
This code can be used for the same idea to create more interesting graphs, like interactive bode plots or frequency spectrums

The LLB contains the following vis:

Mouse in-bound coordinates.vi

Returns the mouse position in global and pan coordinates. Pan coordinates are according Pane Origine which is the little triangle, usually found, in the upper left corner of the front panel. If mouse position is within an object area (inbound) the vi returns TRUE. The vi is called reference to the vi containing the front panel object, position of the front panel object and coordinates of the front panel's pane origin.

Get plot value at mouse position Example.vi

The vi displays the name and x/y values of a plot at mouse position. The Mouse in-bound coordinates.vi is called to check if the mouse points inside a plot area. If so the plot name and x/y values are retrieved. Invoke node GetPlotAtPos is called with the mouse inbound (pan) coordinates to return the number of the nearest plot. The x/y graph property node is called with the plot number to return the plot name. The Map Coords To XY invoke node is called with the mouse inbound coordinates to return the x/y values at the mouse position. The plot name and x/y values are formatted to a string. The string's property node is called with the mouse inbound coordinates to set the position of the string next to the mouse position.

 


Requirements

  • LabVIEW 2012 (or compatible)


Steps to Implement or Execute Code

  1. Open LLB
  1. Run VI

 

Additional Information or References
VI Block Diagram

 Block Diagram.png

 

 **This document has been updated to meet the current required format for the NI Code Exchange.**

 

 

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
Prav_745
Member
Member
on

This code works fine for single graph but if there are more number of graph (suppose 4) on front panel then the position of object changes each time as vertical scroll is used and so that not able plot the values on exact graph location. Is there any way to do it for multiple graph on the same front panel?

masteen
Member
Member
on

You will have to save the plot bounds of all graphs in an array. Then loop through all bounds and check if mouse position is within any of the bounds. if within then enter a case structure with the array index. The case element contains plot name and x/y values for the indexed graph. I have added a version with multiple graphs.

Prav_745
Member
Member
on

Thanks masteen. This is really helpful. But this code is works only if your pane is fixed. In my perticular application this code does not work as i expected. I divided front panel into two pane using horizontal splitter bar. I used more than 2 no. of graphs in second pane. The plot bounds of graph is changes as i move to see suppose 3rd graph and so when i move mouse within bounds it does not show exact value. It will be very helpful for me if you give any idea.

Thanks once again!!!

masteen
Member
Member
on

If you move the Pane - Origin property inside the while loop you should be able to scroll and get correct values.

Regarding multiple panes you must first decide if the mouse is inside a pane. This requires you to calculate the coordinates of the pane in screen (global) coordinates. Then you must check if the mouse is within any plot areas in that pane (as before). The challange is to calculate the global pane coordinates. I have not figured it out yet.Sub vi "Mouse inbound coordinates.vi" will probably have to be edited.

Reshu
Member
Member
on

This was really heilpful when the graph pane is constant not when zoomed in. I want that when we zoom into the graphs , it should show values at those only where data is available. but it shows data where there is no data on the graph.

can anyone help please?

masteen
Member
Member
on

The x/y values displayed are actually interpolated values between two data points in the plot.To display the actual x/y values in XY Graph when the mouse is close to a x/y data point you will have to:

1. Index the XY Graph array with plot number (Plot Num) to extract the plotted data series

2. Search the x values of the plotted data series for the x value nearest to the invoke node x value

3. If the two x values are within let say 10% of each other then display the found x value and its corresponding y value

You can use Threshold 1D Array vi to search XY Graph. It will return the fractional index of the x value in XY Graph