01-22-2007 06:04 PM
01-23-2007 02:38 PM
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
01-24-2007 12:02 PM
01-24-2007 01:34 PM
01-24-2007 01:41 PM
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
01-24-2007 02:52 PM
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);
}
01-25-2007 08:50 PM
_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'