Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

nearest point on scatterplot

Is there a direct way to get the nearest point from xaxis-yaxis values?
0 Kudos
Message 1 of 7
(4,560 Views)

Hi Sof,

I'm afraid that I need a little more clarification to answer your question.

When you say nearest point, do you mean the nearest plot? How are the x and y values obtained?

If you want to snap to the closest plot when you click on a graph, you may want to try implementing a mouse event for PlotAreaMouseDown. I have included a code snippet shown below:

private void OnPlotAreaMouseDown(object sender, MouseEventArgs e)
{
    XYPlot plot = graph.GetPlotAt(e.X, e.Y);
    if (plot != null)
        xyCursor1.Plot = plot;
}

Hopefully this helps.

Matt M.
NI

0 Kudos
Message 2 of 7
(4,546 Views)
I need the nearest point on a scatterplot when the user clicks the mouse on the plotarea.
0 Kudos
Message 3 of 7
(4,533 Views)
Hi Sof,
 
There are a few things you could look at. In the most recent versions of Measurement Studio, an InverseMapValue function has been implemented. This will return a value based on the X and Y values of your mouse pointer with respect to your graph. Documentation on this function can be found in your MStudio help by using this URL in the help: ms-help://NI.MeasurementStudio.2005/NINETUI/html/NationalInstruments.UI.NumericPointerStyle.InverseMapValue.html
 
If you are still using an older version of Measurement Studio or you would like to see a code example, you may want to look at this thread. It contains a version of inverse plotting and a customer example of its implementation.
 
Matt M.
NI
0 Kudos
Message 4 of 7
(4,525 Views)

Yea, I have already implemented that and it works great.  It just gives the x,y which is good but I would like the point on the graph.

 

If it can't be done, ok.  I can roll my own.  I was hoping this was already done.

Scott

0 Kudos
Message 5 of 7
(4,524 Views)

Hi Scott,

You're right that the InverseMap methods return the x and y values. Once these are returned, you have to update your cursor's x and y points to the new points. It then depends on your cursor's snap mode. If it is set to "ToPlot" it will snap to the nearest plot. If it is set to "NearestPoint" it will snap to the nearest point.

I have included an example of how I did this below. You'll notice that I used the InverseMapDataPoint method instead of the method I described earlier.

If you want to get more specific information from the points, you now have the x and y values to do so.

Regards,

Matt M.
NI

private void xyDataScatterGraph_PlotAreaMouseDown(object sender, MouseEventArgs e)
 {
            double x;
            double y;
            xyDataScatterGraph.Plots[0].InverseMapDataPoint(xyDataScatterGraph.Bounds, new PointF(e.X, e.Y), out x, out y);

            xBox.Text = x.ToString();
            yBox.Text = y.ToString();
            xyCursor1.MoveCursor(x, y);
}

0 Kudos
Message 6 of 7
(4,520 Views)
Matt,
 
You gave me an idea with the xycursor.  I made a xycursor on the plot, made it not visible cause I don't want it displayed.  I set the cursor to snap to points on plot and did the following:
 

double x=0, y=0;

PointF pt = new PointF(e.X, e.Y);

_PointPlot.InverseMapDataPoint(_PointGraph.PlotAreaBounds,pt,

out x, out y);

xyCursor1.MoveCursor(x, y);

double x=xyCursor1.XPosition;

double y = xyCursor1.YPosition;

The cursor gets snapped to the point on the plot.  That gave me the point of the plot.  Thanks for the help.  It works real nice

Scott O'

0 Kudos
Message 7 of 7
(4,503 Views)