Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

WPF graph - select horizontal range

Solved!
Go to solution

Hi,

I use WPF graph from MS2015, I want to allow selection of horizontal range (without zoom) so that the user can see the selected range.

1. How I allow to select horizontal range in the graph?

2. The graph Data is ChartCollectionAnalogWaveform<double> , how can I access the data of the selected range only (I want to show statistics of this data) ?

 

0 Kudos
Message 1 of 3
(4,319 Views)
Solution
Accepted by topic author Dudiamar

What you describe sounds like a perfect fit for the RangeCursor. For example:


    XAML
    <ni:Graph x:Name="graph" ...>
        <ni:Graph.Children>
            <ni:RangeCursor x:Name="rangeCursor"/>
        </ni:Graph.Children>
    </ni:Graph>

    Code
    foreach( IPlot plot in graph.AllPlots ) {
        var values = rangeCursor.RetrieveValues( plot );
        using( var xValues = values[0] )
        using( var yValues = (Buffer<double>)values[1] ) {
            double average = yValues.Average( );
            string example = string.Format( "Plot {0} average over [{1:0}]: {2:0.##}", plot.Index, rangeCursor.ActualHorizontalRange, average );
            // ...
        }
    }

~ Paul H
0 Kudos
Message 2 of 3
(4,306 Views)

That was easy!

Thanks, it works for me.

0 Kudos
Message 3 of 3
(4,282 Views)