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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章