采用繪制直線的方法:
創(chuàng)新互聯(lián)建站專業(yè)為企業(yè)提供臨清網(wǎng)站建設(shè)、臨清做網(wǎng)站、臨清網(wǎng)站設(shè)計、臨清網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計與制作、臨清企業(yè)網(wǎng)站模板建站服務(wù),十余年臨清做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡(luò)服務(wù)。
你給出了9個點坐標;
(2,0.8)、(3,0.6)、(4,0.5)、(5,0.4)、..........
把這些相鄰的點之間用直線連接起來,就是折線了。
VB6可以在窗體上或者PictureBox里繪制圖形,語句為:
對象.Line (x1,y1)-(x2,y2)
其中:(x1,y1)和(x2,y2)分別是兩個點的坐標。
'我的數(shù)據(jù)是隨機生成的,方法就是這樣啦,你參考,希望對你有幫助:
'我是在窗體上畫的,在圖片中也是一樣的,本例僅作演示
Option Explicit
Private Sub Form_click()
Cls
Dim i, j As Single
Me.Scale (-1, 10)-(25, -1) '定義坐標系,原點靠近左下角
Line (-1, 0)-(25, 0) '畫x軸
Line (0, -1)-(0, 10) '畫Y軸
For i = -1 To 25 Step 1 '畫X軸刻度
If i 0 Then
Line (i, 0)-(i, 0.2)
CurrentX = i - 0.3: CurrentY = -0.2
Print i
End If
Next
For j = -1 To 10 '畫Y軸刻度
If j 0 Then
Line (0, j)-(0.3, j)
CurrentX = -0.7: CurrentY = j + 0.1
Print j
End If
Next
CurrentX = -0.4: CurrentY = -0.2
Print "0" '畫原點
CurrentX = 0.5: CurrentY = 9.5
Print "Y"
CurrentX = 24: CurrentY = 0.5
Print "X"
Randomize
CurrentX = 1: CurrentY = Format(Rnd * 10, "0.00")
For i = 2 To 24
Line -(i, Format(Rnd * 10, "0.00")) '這里是隨機生成的數(shù)據(jù)!
Next
End Sub
'==================下面在圖片框中畫圖,單擊圖片框即可繪制==========
Option Explicit
Private Sub Form_load()
Picture1.Move 0, 0, Me.Width, Me.Height
Picture1.AutoRedraw = True
End Sub
Private Sub Form_Resize()
Picture1.Move 0, 0, Me.ScaleWidth, Me.ScaleHeight
Picture1_Click
End Sub
Private Sub Picture1_Click()
Picture1.Cls
Dim i, j As Single
Picture1.Scale (-1, 10)-(25, -1) '定義坐標系,原點靠近左下角
Picture1.Line (-1, 0)-(25, 0) '畫x軸
Picture1.Line (0, -1)-(0, 10) '畫Y軸
For i = -1 To 25 Step 1 '畫X軸刻度
If i 0 Then
Picture1.Line (i, 0)-(i, 0.2)
Picture1.CurrentX = i - 0.3: Picture1.CurrentY = -0.2
Picture1.Print i
End If
Next
For j = -1 To 10 '畫Y軸刻度
If j 0 Then
Picture1.Line (0, j)-(0.3, j)
Picture1.CurrentX = -0.7: Picture1.CurrentY = j + 0.1
Picture1.Print j
End If
Next
Picture1.CurrentX = -0.4: Picture1.CurrentY = -0.2
Picture1.Print "0" '畫原點
Picture1.CurrentX = 0.5: Picture1.CurrentY = 9.5
Picture1.Print "Y"
Picture1.CurrentX = 24: Picture1.CurrentY = 0.5
Picture1.Print "X"
Randomize
Picture1.CurrentX = 1: Picture1.CurrentY = Format(Rnd * 10, "0.00")
For i = 2 To 24
Picture1.Line -(i, Format(Rnd * 10, "0.00")) '這里是隨機生成的數(shù)據(jù)!
Next
End Sub
一個例子:
窗體上有一個按鈕 一個能顯示折線圖的控件(我不大知道應(yīng)該用哪個控件)
現(xiàn)有十二個數(shù) 設(shè)其為13-24
點擊按鈕時圖片顯示為一折線圖 折線圖為十二個點的連線 (1,13)(2,14)(3,15)(4,16)(5,17).....(12,24)
請教如何編寫程序
回答:
控件用MsChart,在Microsoft Chart Control 6.0(OLEDB)。
Private Sub Form_Load()
Dim CData(1 To 2, 1 To 24) As Variant
mctChart.chartType = VtChChartType2dLine
For i=1 To 12
CData(1,i)=i '1代表第一個數(shù)據(jù)
Next i
For i=13 To 24 '2代表第二個數(shù)據(jù)
CData(2,i)=i
Next i
mctChart.ChartData = CData
End Sub
參考資料: