line函数出问题
今天用picturebox控件写line函数,但是发现什么也没有绘制出来
下面是写的绘制过程,用于别的地方调用,是否哪儿出问题?检查半天没发现
调试不报错,就是什么东西也没有
里面的值已经在别的过程中赋值了
主要功能也做了标注,也很简单,就是个堆积图样子
Public Sub passratechart(obj As PictureBox, p() As Integer, cp() As Integer, np() As Integer, num As Integer)
Dim hone As Integer
Dim sum As Integer
obj.Cls
hone = num / 20
obj.Scale (-hone, 1.1)-(num + hone, -0.1) '设置坐标系
obj.Line (0, 0)-(num, 0) '绘制绘图区边框
obj.Line (0, 0)-(0, 1)
obj.Line (num, 0)-(num, 1)
obj.Line (0, 1)-(num, 1)
For i = 0 To num - 1
obj.Line (1 + i, 0)-(1 + i, 0.01) '设置横轴刻度
Next i
For i = 0 To 9
obj.Line (0, 0.1 * i + 0.1)-(num, 0.1 * i + 0.1) '设置纵轴刻度
Next i
For i = 0 To 10
obj.CurrentX = -hone: obj.CurrentY = 0.1 * i '设置纵轴数值
Print Format(0.1 * i, "0%")
Next i
For i = 0 To num - 1 '绘制堆积图
sum = p(i) + cp(i) + np(i)
obj.Line (0.25 + i, 0)-(0.75 + i, p(i) / sum), vbGreen, BF
obj.Line (0.25 + i, p(i) / sum)-(0.75 + i, (p(i) + cp(i)) / sum), vbYellow, BF
obj.Line (0.25 + i, (p(i) + cp(i)) / sum)-(0.75 + i, 1), vbRed, BF
Next i
MsgBox num
End Sub
[解决办法]
这是我的测试:
Public Sub passratechart(obj As PictureBox, p() As Integer, cp() As Integer, np() As Integer, num As Integer) Dim hone As Integer Dim sum As Integer obj.Cls hone = num / 20 obj.Scale (-hone, 1.1)-(num + hone, -0.1) '设置坐标系 obj.Line (0, 0)-(num, 0) '绘制绘图区边框 obj.Line (0, 0)-(0, 1) obj.Line (num, 0)-(num, 1) obj.Line (0, 1)-(num, 1) For i = 0 To num - 1 obj.Line (1 + i, 0)-(1 + i, 0.01) '设置横轴刻度 Next i For i = 0 To 9 obj.Line (0, 0.1 * i + 0.1)-(num, 0.1 * i + 0.1) '设置纵轴刻度 Next i For i = 0 To 10 obj.CurrentX = -hone: obj.CurrentY = 0.1 * i '设置纵轴数值 Print Format(0.1 * i, "0%") Next i For i = 0 To num - 2 '绘制堆积图 sum = p(i) + cp(i) + np(i) obj.Line (0.25 + i, 0)-(0.75 + i, p(i) / sum), vbGreen, BF obj.Line (0.25 + i, p(i) / sum)-(0.75 + i, (p(i) + cp(i)) / sum), vbYellow, BF obj.Line (0.25 + i, (p(i) + cp(i)) / sum)-(0.75 + i, 1), vbRed, BF Next i MsgBox num End SubPrivate Sub Form_Load()Picture1.AutoRedraw = TrueDim a(2) As IntegerDim b(2) As IntegerDim c(2) As Integera(0) = 100: a(1) = 400: a(2) = 800b(0) = 1200: b(1) = 1400: b(2) = 1800c(0) = 2200: c(1) = 2400: c(2) = 2800passratechart Picture1, a, b, c, 4End Sub