05-29-2024 07:33 AM
Hello,
Four years ago, i posted a question on about to get the clic position on NI Scratter graph (https://forums.ni.com/t5/Measurement-Studio-for-NET/Maker-on-ScatterGraph-at-mouse-clic-position/m-p...)
Now I want to do the same but on wpf graph element.
Can you help me ?
Thx.
F.
Solved! Go to Solution.
05-30-2024 09:30 AM
I believe "how to set cursor on the position I clicked on the graph?" has the answer to your question: subscribing to the PlotAreaMouseLeftButtonDown event, you can use GetPlotAreaPosition to retrieve the click location (and then apply that screen position to a cursor or annotation child in the graph).
05-31-2024 01:26 AM
Well sort of, the previous post gave me the coordinates of the point in the graphic referencial not the position of the clic in pixel
05-31-2024 09:53 AM
For the pixel screen position, you can use the standard WPF GetPosition
method on the MouseButtonEventArgs
parameter in your event handler.
06-03-2024 12:53 AM
Hello
Not the pixel screen position.
For this screen, when I clic on the blue dot, I want X = 1 and Y = 1 and so on with the different color.
The winform version gave me an float value between 0 and 1 representing the position on the axis.
Thx.
06-03-2024 10:22 AM
Ah, sorry for the confusion! It can be tricking when dealing with multiple coordinate systems (WPF screen pixels, screen positions within the plot area, scaled relative values, and data values).
To get the "X,Y" data position of a point, you can use the ScreenToData
method on the plot area position. The returned values will match the type of the axes used by the specified plot. Assuming you have the default Axis<double>
type, this would look like:
var plot = graph.AllPlots[0]; // (using the first plot in the graph for this example)
Point screen = graph.GetPlotAreaPosition(e);
IList data = graph.ScreenToData(plot, screen);
double x = (double)data[0];
double y = (double)data[1];
Note that this returns the equivalent data value for the pixel position of the mouse. If you want to find the closest point within your data, you can use FindNearestValue
with the relative click position from ScreenToRelative
:
Point screen = graph.GetPlotAreaPosition(e);
Point relative = graph.ScreenToRelative(screen);
var nearest = graph.FindNearestValue(plot, relative, new GraphQueryArgs(PlotsToSearch.Any));
06-04-2024 04:32 AM
Hi,
Perfect ! 😁
Thank you for your help !