十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
采用绘制直线的方法:
创新互联建站专业为企业提供临清网站建设、临清做网站、临清网站设计、临清网站制作等企业网站建设、网页设计与制作、临清企业网站模板建站服务,十余年临清做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。
你给出了9个点坐标;
(2,0.8)、(3,0.6)、(4,0.5)、(5,0.4)、..........
把这些相邻的点之间用直线连接起来,就是折线了。
VB6可以在窗体上或者PictureBox里绘制图形,语句为:
对象.Line (x1,y1)-(x2,y2)
其中:(x1,y1)和(x2,y2)分别是两个点的坐标。
'我的数据是随机生成的,方法就是这样啦,你参考,希望对你有帮助:
'我是在窗体上画的,在图片中也是一样的,本例仅作演示
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")) '这里是随机生成的数据!
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")) '这里是随机生成的数据!
Next
End Sub
一个例子:
窗体上有一个按钮 一个能显示折线图的控件(我不大知道应该用哪个控件)
现有十二个数 设其为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代表第一个数据
Next i
For i=13 To 24 '2代表第二个数据
CData(2,i)=i
Next i
mctChart.ChartData = CData
End Sub
参考资料: