Microsoft Chart Control: Prevent episodes from appearing in a legend

In the MS Chart control (which they bought from Dundas), I have three series to draw.

Two of the series should have an entry in the legend, but the third should not.

I tried these lines of code, but no one works:

Chart c = new Chart(); ChartArea ca = c.ChartAreas.Add("main"); Legend lg = c.Legends.Add("mainLegend"); Series s1 = c.Series.Add("s1"); Series s2 = c.Series.Add("s2"); Series s3 = c.Series.Add("s3"); // ... populate the 3 series with data... s1.Legend = "mainLegend"; s2.Legend = "mainLegend"; // I've tried these: s3.Legend = ""; // gives an error about a nonexistent legend named '' s3.LegendText = ""; // just shows "s3" in the legend 

How to prevent a series from appearing in a legend?

+6
mschart
source share
1 answer

Using:

 s3.IsVisibleInLegend = false; 

Disclaimer: tested only in (ASP) .Net 4, VS 2010. Your mileage may vary ...

+11
source share

All Articles