我有一个奇怪的问题,我是一个初学者制作小程序使用列表框解决一些统计数据并显示 2 个图表问题是当我尝试将前 3 个主列表框保存到 txt 文件并再次加载并进行相同的过程时在保存一切正常之前除了一个具有正确绘制的阶梯线但在X轴上放大的图表在保存之前是不同的,并且根据阶梯线中的点绘制了另一条交叉线,它绘制在与保存之前不同的错误位置
即使我为交叉线输入特定的 X、Y 值,在保存之前它看起来也不一样
这是保存按钮的代码
Dim i As Integer
Dim w As IO.StreamWriter
Dim strFilename As String
SaveFileDialog1.Filter = "Text Files (*.txt)|*.txt"
SaveFileDialog1.FileName = "Table"
SaveFileDialog1.Title = "Save Table"
SaveFileDialog1.OverwritePrompt = True
If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
strFilename = SaveFileDialog1.FileName
w = New IO.StreamWriter(strFilename)
For i = 0 To lstFrom.Items.Count - 1
w.WriteLine(lstFrom.Items.Item(i))
Next
w.WriteLine("*")
For i = 0 To lstFrom.Items.Count - 1
w.WriteLine(lstTo.Items.Item(i))
Next
w.WriteLine("**")
For i = 0 To lstFrom.Items.Count - 1
w.WriteLine(lstF.Items.Item(i))
Next
w.Close()
End If
这是打开按钮的代码
ClearAll()
Dim strFileName As String
With OpenFileDialog1
.Filter = "Text Files (*.txt)|*.txt"
.Title = "Open Table"
End With
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
strFileName = OpenFileDialog1.FileName
Dim myreader As New StreamReader(strFileName)
Dim line As String
line = myreader.ReadLine()
Do Until line = "*"
lstFrom.Items.Add(line)
line = myreader.ReadLine()
Loop
Do Until line = "**"
lstTo.Items.Add(line)
line = myreader.ReadLine()
Loop
Do Until line = ""
lstF.Items.Add(line)
line = myreader.ReadLine()
Loop
myreader.Close()
lstTo.Items.Remove(lstTo.Items(0)) ' that's remove the "*"
lstF.Items.Remove(lstF.Items(0)) ' That's remove the "**"
AllWork()
End If
AllWork() 是相同的方法 使整个过程和显示图表
这是在打开按钮中重新绘制损坏图表的所有代码
这是来自 ClearAll() 方法
Chart2.Series(0).Points.Clear()
Chart2.Series(1).Points.Clear()
Chart2.Series(2).Points.Clear()
Chart2.Series(3).Points.Clear()
Chart2.Series(4).Points.Clear()
这是在 AllWork() 方法中
Chart2.Series(0).Points.Clear()
Chart2.Series(1).Points.Clear()
Chart2.Series(2).Points.Clear()
Chart2.Series(3).Points.Clear()
Chart2.Series(4).Points.Clear()
For i = 0 To lstVariableFrequency.Items.Count - 1
If lstVariableFrequency.Items(i) = dblHighestVariableFrequency Then
dblF1 = lstVariableFrequency.Items(i - 1)
dblF2 = lstVariableFrequency.Items(i + 1)
dblClassBoundry2 = lstTo.Items(i) - lstFrom.Items(i)
dblVersusF = lstFrom.Items(i)
Chart2.Series(0).Points.AddXY(lstFrom.Items(i - 1), lstVariableFrequency.Items(i - 1))
Chart2.Series(0).Points.AddXY(lstFrom.Items(i), lstVariableFrequency.Items(i))
Chart2.Series(0).Points.AddXY(lstFrom.Items(i + 1), lstVariableFrequency.Items(i + 1))
Chart2.Series(1).Points.AddXY(lstFrom.Items(i), lstVariableFrequency.Items(i - 1))
Chart2.Series(1).Points.AddXY(lstFrom.Items(i + 1), lstVariableFrequency.Items(i))
Chart2.Series(2).Points.AddXY(lstFrom.Items(i), lstVariableFrequency.Items(i))
Chart2.Series(2).Points.AddXY(lstFrom.Items(i + 1), lstVariableFrequency.Items(i + 1))
dblMode = dblVersusF + (dblF2 / (dblF1 + dblF2)) * dblClassBoundry2
Exit For
End If
在打开按钮中设置表示图表中 x 轴的 lstfrom 列表
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
strFileName = OpenFileDialog1.FileName
Dim myreader As New StreamReader(strFileName)
Dim line As String
line = myreader.ReadLine()
Do Until line = "*"
lstFrom.Items.Add(line)
line = myreader.ReadLine()
Loop
此代码设置表示 Y 轴的 lstVariableFrequency 列表
For i = 0 To lstFrom.Items.Count - 1
lstL.Items.Add(lstTo.Items(i) - lstFrom.Items(i))
lstVariableFrequency.Items.Add(lstF.Items(i) / lstL.Items(i))
Next