Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

WPF Graph curve select, and display curve name in ToolTip

Solved!
Go to solution

Hi,

 

How can i make it, display the curve name in ToolTip, if i moved the mouse over the curve?
Or display the curve name fixedly above the curve?
And, how can i select a curve with mouse click?
Possible?

 

Regards,
Tamas

 

P.S.: VS2013 Community & MS2015 Standard

0 Kudos
Message 1 of 3
(3,266 Views)
Solution
Accepted by topic author galtamas88

Using the tool tip logic from WPF graph display point value on hover, and the GetPlotAt function, here is an example that uses mouse clicks to select plots in a graph:

 

public partial class MainWindow : Window {

    private Plot _selectedPlot;

    public MainWindow( ) {
        InitializeComponent( );

        // (Optional) Turn on hit testing for drawn lines, in addition to actual data.
        graph.HitTestMode = PlotHitTestMode.RenderedInterpolation;

        // Update tool tips to show quickly and for a long time.
        ToolTipService.SetInitialShowDelay( graph, 0 );
        ToolTipService.SetShowDuration( graph, int.MaxValue );

        // Populate graph with example plots and data.
        graph.BeginInit( );
        var plotBrushes = new[] { Brushes.Red, Brushes.Orange, Brushes.Green, Brushes.Blue };
        for( int i = 0; i < plotBrushes.Length; ++i ) {
            string label = "Plot " + (i + 1);
            var renderer = new LinePlotRenderer { Stroke = plotBrushes[i] };
            var plot = new Plot( label ) { Renderer = renderer };
            graph.Plots.Add( plot );

            graph.Data[i] = new[] { i, i + 1 };
        }
        graph.EndInit( );

        // Monitor graph plot area for mouse clicks.
        graph.PlotAreaMouseLeftButtonDown += OnPlotAreaMouseLeftButtonDown;
    }

    private void OnPlotAreaMouseLeftButtonDown( object sender, MouseButtonEventArgs e ) {
        // Check if a new plot was shown at the current position.
        Point screenPosition = e.GetPosition( graph );
        var plot = (Plot)graph.GetPlotAt( screenPosition );
        if( plot == null || plot == _selectedPlot )
            return;

        // De-select the previous plot, if it exists.
        if( _selectedPlot != null ) {
            ((LinePlotRenderer)_selectedPlot.Renderer).StrokeThickness = 1.0;
            ((ToolTip)graph.ToolTip).IsOpen = false;
        }

        // Select the new plot, and show a tool tip.
        _selectedPlot = plot;
        ((LinePlotRenderer)plot.Renderer).StrokeThickness = 2.0;
        graph.ToolTip = new ToolTip { Content = string.Format( "'{0}' selected", plot.Label ), IsOpen = true };
    }
}

 

Regarding "display the curve name fixedly above the curve", the easiest approach would probably be to use a PointAnnotation to display a label at a particular position (probably hiding the target and arrow).

~ Paul H
Message 2 of 3
(3,256 Views)

Hi,

 

thanks for your reply!

It's working good!

 

Regards,

Tamas

0 Kudos
Message 3 of 3
(3,188 Views)