2016-01-24 204 views
0

我需要爲我正在處理的項目繪製一些圖形,此刻正嘗試使用oxyplot庫在窗體窗體上繪製圖形。我現在寫的代碼是:使用oxyplot在窗體上繪製圖形(vb.net)

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 

我不確定如何從這裏開始實際繪製圖形到窗體上。還有沒有任何oxyplot文檔專門爲vb.net作爲唯一可以找到的形式爲c#

回答

0

我也努力尋找一種方法來在VB.NET窗口窗體上實現Oxyplot。

最簡單的方法仍然是通過工具箱將圖表添加到窗體窗體。爲此,您必須先將Oxyplot控件添加到工具箱(例如,工具>選擇工具箱項目...),然後在.NET組件標籤上瀏覽並在您的項目bin文件夾中找到OxyPlot.WindowsForms.dll。 這個步驟對我來說很長時間沒有任何控制,但是我在卸載Oxyplot軟件包並將其放回之後已經實現了。 完成後,您應該可以通過拖放操作在工具箱中爲表單添加新的「PlotView1」PlotView實例。放置它,調整它的大小,按照你想要的方式設置它。

然後在Form1.Designer.vb,我已經加入了「Plotview1」和「Form1的」塊之間在InitializeComponent()分幾行添加系列和擁有的東西顯示出來:

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 

由於我不是一個普通的程序員,我期望有更合適的方法來編碼這個樣本。