Click here to Skip to main content
14,420,468 members
Rate this:
Please Sign up or sign in to vote.
See more:
I hope someone might be able to help with another question re MS Chart.

I have added five series dynamically to my chart, using the following procedure in a for loop:

private void addSeries(string nme, Color clr)
    {
        Chart1.Series.Add(nme);
        Chart1.Series[nme].Name = nme;
        Chart1.Series[nme].ChartType = SeriesChartType.Line;
        Chart1.Series[nme].BorderWidth = 2;
        Chart1.Series[nme].MarkerStyle = MarkerStyle.Circle;
        Chart1.Series[nme].XValueMember = "theDate";
        Chart1.Series[nme].YValueMembers = nme;
        Chart1.Series[nme].Legend = "Legend1";
        Chart1.Series[nme].Color = clr;
    }


Now, I want to be able to enable/disable each series via a button click, but when I try I'm getting an error message to the effect that the series (never gets past the first one in the loop) cannot be found in the SeriesCollection: "A chart element with the name MD could not be found in the SeriesCollection". I thought that calling the Add method of the Series object would add the named Series to the SeriesCollection. How, can I ensure that dynamically created series are added to the collection?

Thanks


Steve
Posted
Updated 18-Apr-13 1:01am
v2
Comments
Prasad Khandekar 18-Apr-13 11:16am
   
Perhaps this CP artilce (http://www.codeproject.com/Articles/65803/A-Guide-to-using-MSChart-for-NET) will help you.
Steve I 19-Apr-13 11:12am
   
Thanks, Prasad, I checked this out but it didn't give any information regarding the SeriesCollection. I'll keep looking.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

   
Comments
Steve I 20-Apr-13 11:26am
   
Thanks for the link, Maciej, but it doesn't reakky give any help regarding SeriesCollection. My problem is that when I try to loop through the Series that I have created dynamically (so that I can set Enabled to false)I get an error indicating that there are no Series in the SeriesCollection. I'm assuming that this is because I did not create them at design time, but it seems strange to me that they should not get added when created at runtime.

Thanks

Steve

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100