Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I get the Wave form graph X,Y coordinates on mouse click?

I am using NI Studio 7.1 with C# 2003. I am trying to find the X,Y value that the user has clicked on in the Plot Area. The Plot Area Mouse Up event only provides me with the screen coordinates of the click not the actual coords. Any help would be greatly appreciated.
0 Kudos
Message 1 of 7
(5,111 Views)
You can call the graph's GetPlotAt method in the PlotAreaMouseUp event handler to get the plot reference and the x/y data coordinates if the mouse is on a plot point. For example (assuming you have a ScatterGraph or WaveformGraph called graph):


private void OnGraphPlotAreaMouseUp(object sender, MouseEventArgs e)
{
double xData, yData;

XYPlot plot = graph.GetPlotAt(e.X, e.Y, out xData, out yData);
if (plot != null)
{
// ...
}
}

If GetPlotAt returns null, the mouse is not on a plot data point. There are also overloads that will give you just the plot reference, the plot reference and the index into the plot data, or the plot reference, index into the plot data, and the x/y data points.

- Elton
0 Kudos
Message 2 of 7
(5,102 Views)
Thanks, works like a charm just not very intuitive.
0 Kudos
Message 3 of 7
(5,099 Views)
when i try to add a PlotAreaMouseDown event, the function that's generated is...

void CDalitzDlg::OnPlotAreaMouseDownCwgraph1(short FAR* Button, short FAR* Shift, VARIANT FAR* XPos, VARIANT FAR* YPos)
{
//
}

...could someone tell me how to grab the values from the xpos and ypos structs?

I'm just trying to get the values for the plot coords (not the vals in relation to screen coords).

thanks,
ryan
0 Kudos
Message 4 of 7
(5,001 Views)
Use the OnPlotMouseDown event instead of OnPlotAreaMouseDown. You can't get plot coordinates in a plot area event because the graph can have multiple axes with different scales, so arbitrary points can't be mapped to plot coordinates without ambiguity. This is not a problem with plots since they are associated with one X axis and one Y axis.

- Elton
0 Kudos
Message 5 of 7
(5,000 Views)
sorry.. but could you give an example how to use that? it's not too clear to me...

i now have...

void CDalitzDlg::OnPlotMouseDownCwgraph1(short FAR* Button, short FAR* Shift, VARIANT FAR* xData, VARIANT FAR* YData, short FAR* PlotIndex, long FAR* PointIndex)
{
}


...i was assuming that when OnPlotMouseDown() was added, it would be using a different set of data types than whats passed in with the OnPlotArea function.

thanks again,
Ryan
0 Kudos
Message 6 of 7
(4,992 Views)
Hello Ryan,

It looks like you are on the correct track. The PlotMouseDown event has parameters xData and yData which you will want to use. This differs from the PlotAreaMouseDown event which has parameters xPos and yPos. I hope that this information helps you out.

Regards,
Kevin L.
Applications Engineer
National Instruments
0 Kudos
Message 7 of 7
(4,946 Views)