C# - OxyPlot how to add plot to windows form

user3646105 picture user3646105 · Nov 4, 2014 · Viewed 9.5k times · Source

Trying out OxyPlot, installed and referenced packages. Copying and pasting the example from here http://docs.oxyplot.org/en/latest/getting-started/hello-windows-forms.html but it doesn't recognize plot1 from the last line. I am guessing because the control isn't added to the form. How do I add it? I don't see it in the toolbox, and I tried adding the control to the toolbox and can't find it anywhere. Thanks.

Answer

Waleed Shah picture Waleed Shah · Nov 12, 2014

You may add the Plot Control Manually by appending these lines in the Form designer under the initialize component method.

private void InitializeComponent()
{
    this.plot1 = new OxyPlot.WindowsForms.PlotView();
    this.SuspendLayout();
    // 
    // plot1
    // 
    this.plot1.Dock = System.Windows.Forms.DockStyle.Bottom;
    this.plot1.Location = new System.Drawing.Point(0, 0);
    this.plot1.Name = "plot1";
    this.plot1.PanCursor = System.Windows.Forms.Cursors.Hand;
    this.plot1.Size = new System.Drawing.Size(500,500);
    this.plot1.TabIndex = 0;
    this.plot1.Text = "plot1";
    this.plot1.ZoomHorizontalCursor = System.Windows.Forms.Cursors.SizeWE;
    this.plot1.ZoomRectangleCursor = System.Windows.Forms.Cursors.SizeNWSE;
    this.plot1.ZoomVerticalCursor = System.Windows.Forms.Cursors.SizeNS;
    this.Controls.Add(this.plot1);

    //
    // other comtrols
    //

}
private OxyPlot.WindowsForms.PlotView plot1;