[RESOLVED] Howto reset a chart programatically
Hi all,
Hope someone can assist with this query :-
I've a chart control on a windows form & am using the following code to populate it :-
Code:
' Create a data series
Dim series1 As New Series()
Dim series2 As New Series()
Dim series3 As New Series()
' Add data points to the first series
series1.Points.Add(L_Data_1)
series2.Points.Add(L_Data_2)
series3.Points.Add(L_Data_3)
' Add series to the chart
Chart.Series.Add(series1)
Chart.Series.Add(series2)
Chart.Series.Add(series3)
' Charting the main results Graph
Chart.Series(1)("DrawingStyle") = "Wedge"
Chart.Series(1).Color = Color.Green
Chart.Series(1).Font = New Font("Microsoft Sans Serif", 12, FontStyle.Bold)
Chart.Series(1).Label = L_Data_1
Chart.Series(2)("DrawingStyle") = "Wedge"
Chart.Series(2).Color = Color.Yellow
Chart.Series(2).Font = New Font("Microsoft Sans Serif", 12, FontStyle.Bold)
Chart.Series(2).Label = L_Data_3
Chart.Series(3)("DrawingStyle") = "Wedge"
Chart.Series(3).Color = Color.Red
Chart.Series(3).Font = New Font("Microsoft Sans Serif", 12, FontStyle.Bold)
Chart.Series(3).Label = L_Data_3
The data to populate the chart is supplied by the user & then the above code is actioned from a button click event.
I am looking for the user to be able to change the data that is inputted & re-run the graph, so my question is - how do I create a new instance of the chart each time the button is clicked ?
Many thanks for any pointers.
Ciao
Charlie
Re: Howto reset a chart programatically
You don't need to create a new instance of the chart - you just need to clear the Points collection from the series and add the new data. You can then call ResetAutoValues to ensure the Axes are correctly labelled.
Re: Howto reset a chart programatically
Thanks for the help :) it worked a charm.