加载列表框时图表损坏

时间:2013-03-07 10:42:05

标签: .net vb.net charts listbox

我有一个奇怪的问题,我是初学者制作小程序使用列表框解决一些统计数据并显示2个图表 问题是当我尝试将前3个主列表框保存到txt文件并再次加载它并在保存每个东西之前进行相同的处理除了一个图表有阶梯线画右边但是在X轴上缩放是不一样的为了保存,还有另一条交叉线根据Stepline中的点绘制,它在保存之前绘制在一个不同的错误位置

即使我为交叉线输入特定的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

2 个答案:

答案 0 :(得分:0)

尝试将您的开放代码更改为以下

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
    Do Until line = "*"
        line = myreader.ReadLine()
        If line <> "*" Then
            lstFrom.Items.Add(line)
            line = myreader.ReadLine()
        End If
    Loop
    Do Until line = "**"
        line = myreader.ReadLine()
        If line <> "**" Then
            lstTo.Items.Add(line)
            line = myreader.ReadLine()
        End If
    Loop
    Do Until line = ""
        lstF.Items.Add(line)
        line = myreader.ReadLine()
    Loop
    myreader.Close()
    AllWork()
End If

看起来您使用的分隔符(*和/或**)会混淆数据?

答案 1 :(得分:0)

最后我解决了这个问题很简单!我不相信 绘制图表的代码必须具有转换功能的所有问题

Chart2.Series(0).Points.AddXY(CDbl(lstFrom.Items(i - 1)), CDbl(lstVariableFrequency.Items(i - 1)))

感谢任何人阅读了我的问题,并试图解决它