Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microsoft Chart Control: Prevent Series from appearing in Legend

Tags:

mschart

In the MS Chart control (which they bought from Dundas), I have three series that need to be plotted.

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

I've tried these lines of code, but none work:

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 do I prevent the series from appearing in the legend?

like image 406
Jeff Meatball Yang Avatar asked Dec 16 '09 21:12

Jeff Meatball Yang


1 Answers

Use:

s3.IsVisibleInLegend = false;

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

like image 90
grenade Avatar answered Sep 29 '22 09:09

grenade