Reputation: 1
I need to draw some graphs for a project I am working on and at the moment am trying to use the oxyplot library to draw a graph on the windows form. The code I have written at the moment is:
Dim Graph As OxyPlot.PlotModel = New OxyPlot.PlotModel
Graph.Title = "Test"
Dim s1 As OxyPlot.Series.LineSeries
s1.Points.Add(New OxyPlot.DataPoint(2, 7))
s1.Points.Add(New OxyPlot.DataPoint(7, 9))
s1.Points.Add(New OxyPlot.DataPoint(9, 4))
Graph.Series.Add(s1)
End Sub
I am not sure how to proceed from here to actually plot a graph on the form. Also is there any oxyplot documentation on plotting in forms specifically for vb.net as the only ones I can seem to find are for c#
Upvotes: 0
Views: 1425
Reputation: 57
I have also struggled finding a way to implement Oxyplot on windows form in VB.NET.
The simplest way remains adding the plot to the windows form through the toolbox. For that, you have to add the Oxyplot control to the toolbox first (e.g. Tools > Choose Toolbox Items...) and on the .NET component tab browse and find the OxyPlot.WindowsForms.dll in your project bin folder. This step used to fail a long time for me as no control could be found in the dll, but I achieved it after uninstalling the Oxyplot packages and putting them back. Once done, you should be able to add a new "PlotView1" PlotView instance on your form from the toolbox by drag and drop. Place it, resize it, set it up the way you want.
Then on the Form1.Designer.vb, I have added few lines on the InitializeComponent() sub between the "Plotview1" and "Form1" blocks to add your series and to have something showing up:
Private Sub InitializeComponent()
Me.PlotView1 = New OxyPlot.WindowsForms.PlotView()
Me.SuspendLayout()
'
'PlotView1
'
Me.PlotView1.Location = New System.Drawing.Point(12, 12)
Me.PlotView1.Name = "PlotView1"
Me.PlotView1.PanCursor = System.Windows.Forms.Cursors.Hand
Me.PlotView1.Size = New System.Drawing.Size(260, 238)
Me.PlotView1.TabIndex = 0
Me.PlotView1.Text = "PlotView1"
Me.PlotView1.ZoomHorizontalCursor = System.Windows.Forms.Cursors.SizeWE
Me.PlotView1.ZoomRectangleCursor = System.Windows.Forms.Cursors.SizeNWSE
Me.PlotView1.ZoomVerticalCursor = System.Windows.Forms.Cursors.SizeNS
'
'Sample Series
'
plotmod.Title = "Test"
s1.Points.Add(New OxyPlot.DataPoint(2, 7))
s1.Points.Add(New OxyPlot.DataPoint(7, 9))
s1.Points.Add(New OxyPlot.DataPoint(9, 4))
plotmod.Series.Add(s1)
Me.PlotView1.Model = plotmod
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(284, 262)
Me.Controls.Add(Me.PlotView1)
Me.Name = "Form1"
Me.Text = "Window"
Me.ResumeLayout(False)
End Sub
As I am not a regular programmer, I expect there are more appropriate ways of coding this sample.
Upvotes: 0