From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
05-22-2013 07:52 AM
Hello,
Is there an easy way to display the value of a point (with similar formatting to a Cursor) when hovering the mouse over the point? I'm using the WPF graph control (MStudio 2013) with multiple plots graphed on an AxisDouble.(y axis) and AxisPrecisionDateTime (x axis). Let me know if you need any more information and thanks in advance.
Solved! Go to Solution.
05-22-2013 04:02 PM
When a Cursor
is set to snap to data, it uses the FindNearestValue
method to find the nearest plot value. When it is not set to snap to data, it reports the current screen value using the ScreenToData
method. The code example below shows how to use both to display the current value under the mouse in a graph using a tool tip:
private static readonly GraphQueryArgs query = new GraphQueryArgs(
PlotsToSearch.Any, SearchDimensions.HorizontalAndVertical,
SearchDirections.ForwardAndReverse, isInclusive: true );
public MainWindow( ) {
InitializeComponent( );
graph.PlotAreaMouseMove += this.OnPlotAreaMouseMove;
graph.PlotAreaMouseLeave += delegate { graph.ToolTip = null; };
ToolTipService.SetInitialShowDelay( graph, 0 );
ToolTipService.SetShowDuration( graph, int.MaxValue );
}
private void OnPlotAreaMouseMove( object sender, MouseEventArgs e ) {
IPlot plot = graph.AllPlots[0];
Point screenPosition = graph.GetPlotAreaPosition( e );
IList pixelValue = graph.ScreenToData( plot, screenPosition );
string tip = string.Format(
"Absolute value at point {0} is {1}.",
screenPosition, FormatValue( pixelValue ) );
Point relativePosition = graph.ScreenToRelative( screenPosition );
PlotValue nearestValue = graph.FindNearestValue( plot, relativePosition, query );
if( nearestValue != null )
tip += Environment.NewLine + string.Format(
"Nearest value on {0} is {1}.",
nearestValue.PlotObserver.Label,
FormatValue( nearestValue.Value ) );
graph.ToolTip = tip;
}
private static string FormatValue( IList values ) {
return string.Join( ", ", values.Cast<object>( ) );
}
08-20-2013 01:42 PM
Is there any way to make this work if the plot is a scattergraph? In the code, graph is not defined and it turns out it is a Controls.Graph. I have plots on Scattergraphs and I would love to be able to get the nearest point to the mouse and not be limited to requiring the user to click directly on a data point.
Thanks,
Steve
08-20-2013 01:58 PM
Is there any way to do this in WinForms? It seems the point class required by FindNearestValue (systems.windows.point) is WPF specific.
Steve
08-21-2013 10:49 AM
This white paper might give you some useful information.http://www.ni.com/white-paper/10526/en/
08-21-2013 10:58 AM
Looking through the list of ScatterGraph
members, it looks like GetPlotAt
may provide similar functionality in Windows Forms.
You may also want to post your Windows Forms question separately, instead of adding it to an answered WPF question, so that more people will see it.
09-03-2015 03:18 AM
Hello Paul,
i have a chart with multiple plot, i'm trying to get the point (X,Y) on i click on specific plot,
can you help me?
NB: i'm working with VB.NET
09-04-2015 10:31 AM
Hi Akarim,
I'm going to suggest you make a new discussion about this since this thread was already solved and your question seems different. However, this seems like a good place to start.