How to plot in Windows Forms application

Jul 11, 2012 at 10:35 PM

Hello,

 

I would like to make a simple plot in a Windows Forms Application. After pressing a button the plot should be displayed. So far I have done following steps:

1. Created Windows Forms Application project,

2. Added one button that should display the plot,

3. Added OxyPlot Package by choosing Tools->Library Package Manager-> Package Manager Console and printing Install-Package OxyPlot.WindowsForms

4. I chose one Plot from the examples:

[Example("LineSeries")]

       public static PlotModel LineSeries()

       {

           var plotModel1 = new PlotModel();

           plotModel1.LegendSymbolLength = 24;

           plotModel1.Title = "LineSeries";

           plotModel1.Axes.Add();

           plotModel1.Axes.Add();

           plotModel1.Series.Add();

          var linearAxis1 = new LinearAxis();

           linearAxis1.Position = AxisPosition.Bottom;

           plotModel1.Axes.Add(linearAxis1);

           var linearAxis2 = new LinearAxis();

           plotModel1.Axes.Add(linearAxis2);

           var lineSeries1 = new LineSeries();

           lineSeries1.Color = OxyColors.SkyBlue;

           lineSeries1.MarkerFill = OxyColors.SkyBlue;

           lineSeries1.MarkerSize = 6;

           lineSeries1.MarkerStroke = OxyColors.White;

           lineSeries1.MarkerStrokeThickness = 1.5;

           lineSeries1.MarkerType = MarkerType.Circle;

           lineSeries1.Title = "Series 1";

           lineSeries1.Points.Add(new DataPoint(0,10));

           lineSeries1.Points.Add(new DataPoint(10,40));

           lineSeries1.Points.Add(new DataPoint(40,20));

           lineSeries1.Points.Add(new DataPoint(60,30));

           plotModel1.Series.Add(lineSeries1);

           return plotModel1;

       }

End there is my question. I have the code for the button like this:

 

  private void button1(object sender, EventArgs e)

        {

        }

 

How to use the code from [Example("LineSeries")] in button1?

Any help appreciated.

JohnnyP

 

Coordinator
Jul 11, 2012 at 10:43 PM

You need to add an OxyPlot.WindowsForms.Plot control to your Form.

Then set the Model property of that control to the model provided by your LineSeries method.

See Examples/WindowsForms/WindowsFormsDemo/Form1.cs

Jul 11, 2012 at 11:17 PM

Hello Objo,

 

Thanks for the answer. In Examples\WindowsForms\WindowsFormsDemo\ I can find only these flies: OxyPlot.dll, OxyPlot.WindowsForms.dll, WindowsFormsDemo.exe and no Form1.cs

Coordinator
Jul 13, 2012 at 8:32 AM

See the "Source code" tab on top of the page