2017年12月11日 星期一

VB2010-繪製折線圖

VB2010-繪製折線圖


Public Class Form1
    'Boundary of plot
    Const LeftSpan As Integer = 15
    Const TopSpan As Integer = 15
    Const AxYHeight As Integer = 200
    Const AxXWidth As Integer = 350

    'Range of plot
    Const XRangeMax As Integer = 20
    Const YRangeMax As Integer = 30000

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim G As Graphics = Me.CreateGraphics
        Dim I, X, Y As Integer
        Dim LX As Integer = -1000, LY As Integer = -1000
        Dim Data1X(20) As Integer

        Data1X(0) = 27000 : Data1X(1) = 27000 : Data1X(2) = 27000
        Data1X(3) = 27000 : Data1X(4) = 26500 : Data1X(5) = 26500
        Data1X(6) = 26000 : Data1X(7) = 26000 : Data1X(8) = 25500
        Data1X(9) = 25000 : Data1X(10) = 24500 : Data1X(11) = 24000
        Data1X(12) = 24000 : Data1X(13) = 23000 : Data1X(14) = 22000
        Data1X(15) = 22000 : Data1X(16) = 21500 : Data1X(17) = 22000
        Data1X(18) = 22000 : Data1X(19) = 22500 : Data1X(20) = 23000

        G.DrawLine(Pens.Black, LeftSpan, TopSpan, LeftSpan, TopSpan + AxYHeight)
        G.DrawLine(Pens.Black, LeftSpan, TopSpan + AxYHeight, LeftSpan + AxXWidth, TopSpan + AxYHeight)

        For I = 0 To XRangeMax Step 2
            X = I / XRangeMax * AxXWidth + LeftSpan
            G.DrawLine(Pens.Blue, X, TopSpan + AxYHeight - 5, X, TopSpan + AxYHeight + 5)
            G.DrawString((I + 2000), Me.Font, Brushes.Black, X - Me.Font.Size, TopSpan + AxYHeight + 5)
        Next

        For I = 5000 To YRangeMax Step 5000
            Y = AxYHeight - (I / YRangeMax * AxYHeight) + TopSpan
            G.DrawLine(Pens.OrangeRed, LeftSpan - 5, Y, LeftSpan + 5, Y)
            G.DrawString(I, Me.Font, Brushes.Black, LeftSpan + 2, Y - Me.Font.Size / 2)
        Next


        For I = 0 To UBound(Data1X)
            X = I / XRangeMax * AxXWidth + LeftSpan
            Y = AxYHeight - (Data1X(I) / YRangeMax * AxYHeight) + TopSpan
            G.DrawEllipse(Pens.Red, X - 2, Y - 2, 5, 5)

            If LX > 0 Then
                G.DrawLine(Pens.Red, X, Y, LX, LY)
            End If

            LX = X
            LY = Y
        Next
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        End
    End Sub
End Class

沒有留言:

張貼留言

WOKWI LED + MQTT Node-Red SQLite

WOKWI LED + MQTT Node-Red SQLite const char *mqtt_broker = "broker.mqtt-dashboard.com" ; const char *topic1 = "alex9ufo/e...