Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

How to Plot XY Data WPF

Solved!
Go to solution

Plotting on winform is quite simple but I am trying to move to wpf and encountering some issues. How can I plot XY graph with Graph control? In the example below, I just want to plot the signal vs t.  I can find some example for plotting but none is for xy plot

 

            int Fs = 1000;
            double T = 1.000 / Fs;
            int L = 2000;
            double[] t = new double[2000];
            double[] signal = new double[2000];

            for (int i = 0; i < L; i++)
            {
                t[i] = i * T;
                signal[i] = Math.Sin(2 * 3.14 * 50 * t[i]);
            }

                Graph1.DataSource = signal;
0 Kudos
Message 1 of 3
(3,934 Views)

Hello rle 2,

Are you using Measurement Studio? Have you seen the documentation on graphing using WPF?

Customizing Measurement Studio WPF Controls for a Unique User Interface

Zofia
NI Technical Support Engineer
0 Kudos
Message 2 of 3
(3,899 Views)
Solution
Accepted by rle2

To plot XY data, you just need to provide the graph with a type that includes both X and Y values, such as a Point[] (or possibly a ChartCollection <double,double>😞

 

...
Point[] points= new Point[2000]; for (int i = 0; i < L; i++) { points[i].X = i * T; points[i].Y = Math.Sin( 2 * 3.14 * 50 * points[i].X ); }

Graph1.DataSource = points;

 

You may also want to look at the "XYPlotting" example that comes installed with Measurement Studio.

~ Paul H
Message 3 of 3
(3,897 Views)