Using OxyPlot in WindowsForms

3.9k views Asked by At

So far, from what I've seen on the OxyPlot documentation, not much is out there. How do I take x-y points and graph them using OxyPlot?

Here is my attempt at taking two points and graphing them:

var dataModel = new PlotModel { Title = "data plot" };

foreach (var pt in dataProfile)
{
    XYData.Text = String.Format("X:{0} Y:{1}", pt.X,pt.Y);
    dataModel.Series.Add(pt.X, pt.Y); //(obviously wrong here)
    this.plot1.Model = dataModel;
}

What do I need to change/add to: dataModel.Series.Add(pt.X, pt.Y);, so that it adds points? Additionally, how can I plot points over time? (x-y, plotted as time t passes by)

Does anyone know of a good OxyPlot tutorial site (for WinForms), because I cannot find one (apart from the OxyPlot documentation, which is very broad at best).

1

There are 1 answers

6
B.K. On

I know you've mentioned WinForms, but you must be able to get comfortable with looking at all of the examples and all of the source code, regardless of the UI framework being used. Look up oxyplot in your favorite search engine and you'll find plenty of examples on their GitHub page (or whatever repo service they'll use whenever this answer is being looked at).

Anyways, what you want is a ScattierSeries plot. You then add points to it. An example:

    public static PlotModel ExampleScatterSeriesPlot()
    {
        var plotModel1 = new PlotModel();
        plotModel1.Subtitle = "The scatter points are added to the Points collection.";
        plotModel1.Title = "ScatterSeries";
        var linearAxis1 = new LinearAxis();
        linearAxis1.Position = AxisPosition.Bottom;
        plotModel1.Axes.Add(linearAxis1);
        var linearAxis2 = new LinearAxis();
        plotModel1.Axes.Add(linearAxis2);
        var scatterSeries1 = new ScatterSeries();
        scatterSeries1.Points.Add(new ScatterPoint(0.667469348137951, 0.701595088793707));
        scatterSeries1.Points.Add(new ScatterPoint(7.74765135149828, 5.11139268759237));
        scatterSeries1.Points.Add(new ScatterPoint(7.97490558492714, 8.27308291023275));
        scatterSeries1.Points.Add(new ScatterPoint(1.65958795308116, 7.36130623489679));
        scatterSeries1.Points.Add(new ScatterPoint(2.6021636475819, 5.06004851081411));
        scatterSeries1.Points.Add(new ScatterPoint(2.30273722312541, 3.87140443263175));
        scatterSeries1.Points.Add(new ScatterPoint(2.15980615101746, 0.208108848989061));
        scatterSeries1.ActualPoints.Add(new ScatterPoint(0.667469348137951, 0.701595088793707));
        scatterSeries1.ActualPoints.Add(new ScatterPoint(7.74765135149828, 5.11139268759237));
        scatterSeries1.ActualPoints.Add(new ScatterPoint(7.97490558492714, 8.27308291023275));
        scatterSeries1.ActualPoints.Add(new ScatterPoint(1.65958795308116, 7.36130623489679));
        scatterSeries1.ActualPoints.Add(new ScatterPoint(2.6021636475819, 5.06004851081411));
        scatterSeries1.ActualPoints.Add(new ScatterPoint(2.30273722312541, 3.87140443263175));
        scatterSeries1.ActualPoints.Add(new ScatterPoint(2.15980615101746, 0.208108848989061));
        plotModel1.Series.Add(scatterSeries1);
        return plotModel1;
    }

There are a ton of examples under the example browser link I gave you. The above code was snipped from there. So, research all of the available options. OxyPlot is very flexible and I've been able to extend on it easily in my recent project.