2017年12月12日 星期二

[ 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 B As Brush
        Dim I As Integer, J As Integer
        Dim H As Integer, X As Integer, Y As Integer

        Dim Data1A(2) As String
        Dim Data1O(2) As Integer
        Dim Data1P(2) As Integer
        Dim Data1Q(2) As Integer

        Data1A(0) = "楠梓區" : Data1A(1) = "楠梓區" : Data1A(2) = "鼓山區"
        Data1O(0) = 258276 * 0.1 : Data1O(1) = 181845 * 0.1 : Data1O(2) = 7100
        Data1P(0) = 193888 * 0.1 : Data1P(1) = 196936 * 0.1 : Data1P(2) = 10168
        Data1Q(0) = 147458 * 0.1 : Data1Q(1) = 138099 * 0.1 : Data1Q(2) = 9419

        B = New SolidBrush(Color.FromArgb(20, 10, 255))
        G.FillRectangle(B, LeftSpan + AxXWidth + LeftSpan, 50, LeftSpan, 10)
        G.DrawString("面積平方公里 x 10", Me.Font, Brushes.Black, LeftSpan + AxXWidth + LeftSpan * 3, 50)

        B = New SolidBrush(Color.FromArgb(120, 255, 0))
        G.FillRectangle(B, LeftSpan + AxXWidth + LeftSpan, 70, LeftSpan, 10)
        G.DrawString("人口數 x 10", Me.Font, Brushes.Black, LeftSpan + AxXWidth + LeftSpan * 3, 70)

        B = New SolidBrush(Color.FromArgb(255, 200, 0))
        G.FillRectangle(B, LeftSpan + AxXWidth + LeftSpan, 90, LeftSpan, 10)
        G.DrawString("人口密度", Me.Font, Brushes.Black, LeftSpan + AxXWidth + LeftSpan * 3, 90)


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

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

        For I = 0 To UBound(Data1A)
            X = (AxXWidth / (UBound(Data1A) + 2)) * (I + 1) + LeftSpan
            For J = 1 To Len(Data1A(I))
                Y = AxYHeight + TopSpan + TopSpan * J
                G.DrawString(Mid(Data1A(I), J, 1), Me.Font, Brushes.Black, X, Y)
            Next

            Y = AxYHeight + TopSpan

            B = New SolidBrush(Color.FromArgb(20, 10, 255))
            H = AxYHeight * Data1O(I) / YRangeMax
            G.FillRectangle(B, X - 17, Y - H, 15, H)

            B = New SolidBrush(Color.FromArgb(120, 255, 0))
            H = AxYHeight * Data1P(I) / YRangeMax
            G.FillRectangle(B, X, Y - H, 15, H)

            B = New SolidBrush(Color.FromArgb(255, 200, 0))
            H = AxYHeight * Data1Q(I) / YRangeMax
            G.FillRectangle(B, X + 17, Y - H, 15, H)
        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...