我刷新时有一个复制的图表。
事实上,我用这段代码清除了图表:
chrt.Series.Clear()
chrt.Titles.Clear()
然后我再次调用图表功能以在图表中显示值。
当我这样做时,它只是复制调色板。
代码:
connection = New MySqlConnection("server=localhost;userid=root;password='';database= inventory_control")
connection.Open()
Dim cmdstring1 As String = "SELECT COUNT(DISTINCT(quantity)) from inventory"
Dim cmdstring As String = "SELECT category, quantity from inventory"
command = New MySqlCommand(cmdstring, connection)
command1 = New MySqlCommand(cmdstring1, connection)
Dim intResult As Integer = command.ExecuteNonQuery
MsgBox(intResult)
Dim reader As MySqlDataReader
reader = command.ExecuteReader(CommandBehavior.CloseConnection)
'Read data from column
While reader.Read()
strTosplit += reader("category") & " "
strQty += reader("quantity") & ", "
End While
'Remove empty string from array
Dim xValues() As String = strTosplit.Split(New Char() {" "}, StringSplitOptions.RemoveEmptyEntries).Where(
Function(s) Not String.IsNullOrWhiteSpace(s)
).ToArray()
Dim zValues() As String = strQty.Split(New Char() {","})
' Dim xValues() As String =
Dim yValues() As Integer = (From str In zValues
Let isInt = Int32.TryParse(str, value)
Where isInt
Select Int32.Parse(str)).ToArray
connection.Close()
Dim seriesName As String = Nothing
' Note 1 : Clear chart before fill - VERY IMPORTANT and can generate exception if you are generating
' multiple charts in loop and have not included below lines !
chrt.Series.Clear()
chrt.Titles.Clear()
' Give unique Series Name
seriesName = "Articles in Store"
chrt.Series.Add(seriesName)
' Bind X and Y values
chrt.Series(seriesName).Points.DataBindXY(xValues, yValues)
chrt.ChartAreas("ChartArea1").Area3DStyle.Enable3D = False
' If you want to show Chart Legends
chrt.Legends(0).Enabled = True
' If you don't want to show data values and headings as label inside each Pie in chart
chrt.Series(seriesName)("PieLabelStyle") = "Disabled"
chrt.Series("Articles in Store").IsValueShownAsLabel = False
' If you want to show datavalues as label inside each Pie in chart
chrt.Series("Articles in Store").IsValueShownAsLabel = True