我有两个For Next
循环用于将结果发送到Chart
。然而,系列线条混乱。
我理解这个问题,但我无法找到解决方案。 Chart
显示所有点,但我需要将第一个迭代点匹配在一起,将第二个迭代点匹配在一起......等等。
以下是代码:
Dim i as integer
Dim n as integer
Dim speed as decimal
Dim horsepower as decimal
For i=1 to 30 Step 2
For n=1 to 20 Step 1
Dim power as label=CType(GroupBox1.Controls("Label"&n),Label)
Dim txt as textbox=CType(Tabcontrolpanel1.Controls("TextBox"&i),Textbox)
horsepower=Val(power.text)*3.14
speed=Val(txt.Text)*3*5
ChartControl1.Series("Series 1").Points.Add(New Seriespoint(horsepower, speed)
Next
Next
我需要绘制(x,y)(horsepower1,speed1),(horsepower2,speed2)......等等。不(马力1,速度2),(马力1,速度3)
答案 0 :(得分:1)
由于您拥有15速文本框和20马力标签,因此无法完全匹配。但是如果你想用前15个来做,你必须用一个循环来做。
For i=1 to 15
Dim power as label=CType(GroupBox1.Controls("Label"&i),Label)
Dim txt as textbox=CType(Tabcontrolpanel1.Controls("TextBox"&(i*2-1)),Textbox)
horsepower=Val(power.text)*3.14
speed=Val(txt.Text)*3*5
ChartControl1.Series("Series 1").Points.Add(New Seriespoint(horsepower, speed)
Next
如果您有不同的起始索引,则必须将其保存在变量中。
' First matching index
Dim labelIndex As Integer = 1
Dim textboxIndex As Integer = 1
For i=1 to 15
Dim power as label=CType(GroupBox1.Controls("Label"&labelIndex),Label)
Dim txt as textbox=CType(Tabcontrolpanel1.Controls("TextBox"&textboxIndex),Textbox)
horsepower=Val(power.text)*3.14
speed=Val(txt.Text)*3*5
ChartControl1.Series("Series 1").Points.Add(New Seriespoint(horsepower, speed)
' Go to the next matching index
labelIndex += 1
textboxIndex += 2
Next