VB - 图表(系列被添加)

时间:2017-06-11 14:52:47

标签: vb.net graph charts

我有两个单独的图表,但每次我回到不同的图表。它再次添加了系列,导致它破裂。我已经尝试将系列添加到系列集合中,但后来说它无法找到它们。

 Private Sub Finances_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    ChrPriceChange.ChartAreas("ChartArea").AxisX.ScrollBar.Enabled = True
    ChrPriceChange.ChartAreas("ChartArea").AxisX.IsLabelAutoFit = True
    ChrPriceChange.ChartAreas("ChartArea").AxisX.ScaleView.Size = 4
    ChrRoomProfit.ChartAreas("ChartArea").AxisX.ScrollBar.Enabled = True
    ChrRoomProfit.ChartAreas("ChartArea").AxisX.IsLabelAutoFit = True
    ChrRoomProfit.ChartAreas("ChartArea").AxisX.ScaleView.Size = 6
End Sub

Private Sub CmbType_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CmbType.SelectedIndexChanged
    If CmbType.SelectedItem = "Price Change" Then

        ChrPriceChange.Series.Add("Single Room")
        ChrPriceChange.Series.Add("Double Room")
        ChrPriceChange.Series.Add("Family Room")
        ChrPriceChange.Series.Add("per Adult")
        ChrPriceChange.Series.Add("per Child")
        ChrPriceChange.Visible = True
        ChrRoomProfit.Visible = False

        MyConn.ConnectionString = dataFile
        MyConn.Open()
        Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM [Prices] ORDER BY `Last Modified` ASC", MyConn)
        Dim dr As OleDbDataReader = cmd.ExecuteReader
        While dr.Read
            ChrPriceChange.Series("Single Room").Points.AddXY(dr("Last Modified").ToString, dr("Single").ToString)
            If (ChrPriceChange.ChartAreas(0).AxisX.Maximum > ChrPriceChange.ChartAreas(0).AxisX.ScaleView.Size) Then
                ChrPriceChange.ChartAreas(0).AxisX.ScaleView.Scroll(ChrPriceChange.ChartAreas(0).AxisX.Maximum)
            End If
            ChrPriceChange.Series("Double Room").Points.AddXY(dr("Last Modified").ToString, dr("Double").ToString)
            ChrPriceChange.Series("Family Room").Points.AddXY(dr("Last Modified").ToString, dr("Family").ToString)
            ChrPriceChange.Series("per Adult").Points.AddXY(dr("Last Modified").ToString, dr("Adult").ToString)
            ChrPriceChange.Series("per Child").Points.AddXY(dr("Last Modified").ToString, dr("Child").ToString)
        End While
        MyConn.Close()
        cmd.Dispose()
    End If

    If CmbType.SelectedItem = "Room Profit" Then
        ChrRoomProfit.Series.Add("Total Made")

        ChrRoomProfit.Visible = True
        ChrPriceChange.Visible = False

        MyConn.ConnectionString = dataFile
        MyConn.Open()
        Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM [BookingInformation] ORDER BY `Date In` ASC", MyConn)
        Dim dr As OleDbDataReader = cmd.ExecuteReader
        While dr.Read
            ChrRoomProfit.Series("Total Made").Points.AddXY(dr("Date In").ToString, dr("Total").ToString)

            If (ChrRoomProfit.ChartAreas(0).AxisX.Maximum > ChrRoomProfit.ChartAreas(0).AxisX.ScaleView.Size) Then
                ChrRoomProfit.ChartAreas(0).AxisX.ScaleView.Scroll(ChrRoomProfit.ChartAreas(0).AxisX.Maximum)
            End If
        End While
        MyConn.Close()
        cmd.Dispose()
    End If
End Sub

1 个答案:

答案 0 :(得分:1)

意识到这是因为我没有任何东西可以清除它。 ChrPriceChange.Series.Clear