【问题标题】:Using oxyplot to plot graphs on form (vb.net)使用 oxyplot 在表单上绘制图形 (vb.net)
【发布时间】:2016-09-22 21:34:49
【问题描述】:

我需要为我正在处理的项目绘制一些图表,目前我正在尝试使用 oxyplot 库在 windows 窗体上绘制图表。我现在写的代码是:

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

我不确定如何从这里开始在表单上实际绘制图表。还有任何关于在表格中专门为 vb.net 绘制的 oxyplot 文档,因为我似乎唯一能找到的是 c#

【问题讨论】:

    标签: vb.net winforms oxyplot


    【解决方案1】:

    我也一直在努力寻找一种在 VB.NET 中在 Windows 窗体上实现 Oxyplot 的方法。

    最简单的方法仍然是通过工具箱将绘图添加到窗口窗体。为此,您必须首先将 Oxyplot 控件添加到工具箱(例如工具 > 选择工具箱项...),然后在 .NET 组件选项卡上浏览并在项目 bin 文件夹中找到 OxyPlot.WindowsForms.dll。 由于在 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
    

    由于我不是一个普通的程序员,我希望有更合适的方式来编写这个示例。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-16
      • 1970-01-01
      • 1970-01-01
      • 2013-09-02
      • 1970-01-01
      • 1970-01-01
      • 2023-03-12
      相关资源
      最近更新 更多