vb.net中使用zedgraph.dll动态链接库画图

1问题描述

   在程序中用到zedgraph来对图表显示,故而在ui界面中使用zedgraph控件是必不可少的掌握技能。

2案例说明

2.1案例创建

首先从网上下载zedgraph.dll,打开vs,右击zedgraph+数组,添加引用,加入zedgraph.dll
在这里插入图片描述
可下载或自己编写,zedgraph类及相关运行子过程,相关代码如下。

Imports ZedGraph
Public Class ZDG
    Public MyGraph As New ZedGraphControl '声明Zedgraph对象并实例化
    Public Sub ClearCurve(ByVal Graph_Name As ZedGraphControl)
        MyGraph = Graph_Name
        MyGraph.GraphPane.CurveList.Clear()
        MyGraph.GraphPane.GraphObjList.Clear()
        'MyGraph.Refresh()
    End Sub
    Public Sub AddCurve(ByVal Graph_Name As ZedGraphControl, ByVal Curve_Name As String, ByVal x As Array, ByVal y As Array, ByVal colorIndex As Integer)
        MyGraph = Graph_Name
        Select Case colorIndex
            Case 1
                MyGraph.GraphPane.AddCurve(Curve_Name, x, y, Color.Blue, ZedGraph.SymbolType.None)
            Case 2
                MyGraph.GraphPane.AddCurve(Curve_Name, x, y, Color.Red, ZedGraph.SymbolType.None)
            Case 3
                MyGraph.GraphPane.AddCurve(Curve_Name, x, y, Color.Yellow, ZedGraph.SymbolType.None)
            Case 4
                MyGraph.GraphPane.AddCurve(Curve_Name, x, y, Color.Green, ZedGraph.SymbolType.None)
        End Select

        MyGraph.GraphPane.Fill = New ZedGraph.Fill(Color.White, Color.LightSteelBlue)
        'MyGraph.AxisChange()
        MyGraph.Refresh()
    End Sub
    Public Sub Iinitial(ByVal Graph_Name As ZedGraphControl, ByVal Title As String, ByVal XTitle As String, ByVal YTitle As String)
        MyGraph = Graph_Name
        MyGraph.GraphPane.Title.Text = Title
        MyGraph.GraphPane.XAxis.Title.Text = XTitle
        MyGraph.GraphPane.YAxis.Title.Text = YTitle
        MyGraph.GraphPane.XAxis.Scale.Max = 3
        MyGraph.GraphPane.YAxis.Scale.Max = 8
        MyGraph.GraphPane.YAxis.Scale.Min = -2
        MyGraph.GraphPane.YAxis.Scale.MajorStep = 1
        MyGraph.GraphPane.YAxis.Scale.MinorStep = 0.1
        MyGraph.IsShowPointValues = True
    End Sub
End Class

创建ui及相关程序如下,zedgraph图表,使用右击(所有windows窗体),选择选择项,跳出如下界面,浏览来选择。
在这里插入图片描述
界面如下
在这里插入图片描述
代码如下

Imports ZedGraph
Imports System.Windows.Forms
Public Class Form1
    Dim graph As New ZDG

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        graph.Iinitial(ZedGraphControl1, "曲线", " x轴坐标", " y轴坐标")

        Dim x(8) As Double
        Dim y(8) As Double
        Dim i As Integer
        For i = 0 To 8
            x(i) = i / 2
            y(i) = x(i) * x(i) - 1
        Next


        graph.AddCurve(ZedGraphControl1, "", x, y, 1)
    End Sub
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        graph.ClearCurve(ZedGraphControl1)
    End Sub
End Class

3问题解决

初始化无法更新,后再clearcurve子过程中加入,Mygraph.Refresh,加入后功能实现
在这里插入图片描述

4扩展

在这里插入图片描述
改变 ZedGraph.SymbolType.None可改变曲线形式
效果如下

1.ZedGraph.SymbolType.None=10
在这里插入图片描述
2.ZedGraph.SymbolType.None=12
在这里插入图片描述

5参考资料

https://bbs.csdn.net/topics/350085840

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 深蓝海洋 设计师:CSDN官方博客 返回首页