Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

How to plot Timestamp vs data on wpf graph

Sir,

 

I am using wpf graph control in my application. My intention is to plot the data, which consists of Timestamp as X-value and corresponding some float value as Y-value...How can i specify this kind of data to wpf graph?? I have tried the following but this is not correclty displaying the time.

 

I converted timestamp to double value using ToOADate() method and the X-axis i specified as ni:DateTimeAxis..I have supplied the double Point array as a datasource to the graph..But this is not correctly displaying the time...Can this be sorted out??

0 Kudos
Message 1 of 2
(5,801 Views)

The WPF graph has native support for DateTime and PrecisionDateTime values, so you do not need to convert your data to double values first. Simply use a data type that can supply time values, such as AnalogWaveform<TData>. For example:


    // XAML
    <ni:Graph Name="graph">
        <ni:Graph.Axes>
            <ni:AxisDateTime Orientation="Horizontal" />
        </ni:Graph.Axes>
    </ni:Graph>


    // code
    double[] sampleValues = ...;
    WaveformTiming timeValues = WaveformTiming.Create...;

    var waveform = AnalogWaveform<double>.FromArray1D( sampleValues );
    waveform.Timing = timeValues;
    graph.DataSource = waveform;

~ Paul H
0 Kudos
Message 2 of 2
(5,793 Views)