0
votes

I have a chart named Chart1 and default series Series1. The chart is displayed as required but when click on show button again it shows the error message "An unhandled exception of type 'System.ArgumentException' occurred in System.Windows.Forms.DataVisualization.dll

Additional information: A chart element with the name 'Series1' could not be found in the 'SeriesCollection'. " Any idea please?

    Chart1.DataSource = ds.Tables("tblABC")
    Dim Series1 As Series = Chart1.Series("Series1")
    Series1.Name = "Customer Collection"

    Chart1.Series(Series1.Name).XValueMember = "remarks"
    Chart1.Series(Series1.Name).YValueMembers = "Total"
    Chart1.Series(Series1.Name).IsValueShownAsLabel = True
1
You are changing then Series name from "Series1" to "Customer Collection".TnTinMn
Thanks for the suggestion.Darpan Dahal

1 Answers

0
votes

Make sure that you aren't doing a Chart.Series.Clear() anywhere as in that case you wouldn't have a Series1 in your SeriesCollection. Thus, the error.

Alternatively, you could create the Series that you want instead of renaming the Series1. Since I'm pretty sure you cleared your series at some point change the second line in your example above to:

Dim Series1 As Series = Chart1.Series.Add("Customer Collection")

Here you are creating a new series, calling it Customer Collection and assigning it to your Series1 variable so that you can use it later on in your code as you're currently doing with the Series1.Name