Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selectively hiding series in a C# chart

Lets say I have a chart with 2 series on it. Then for each series, I have a checkbox to say whether I want to see them or not. Assume that I originally plot both, and afterwards, wanted to hide either of them. What is the best way to do this?

I know I could just Clear() it and then AddXY() them back in, but is there a faster way to do it?

My attempted ideas:


1. Set a visibility property to true/false depending on checkbox.
There is No visibility Property

2. Copy Points Collection to a variable, clear, and put back in.
Series[].Points is read-only

3. Copy Series to a variable, clear the points, and put back in.
Apparently it stores the Series as a reference when I try this, and I cannot find a copy command.

So I am apparently going about this the wrong way. How would you dynamically allow chart to have different series hidden?

like image 387
Xantham Avatar asked Feb 21 '13 21:02

Xantham


2 Answers

There's another way to do this without hiding the legend.

Simply say:

Chart.Series[0].Color = Color.FromArgb(0, 0, 0, 0); //sets color to transparent

You can reset to Color.Empty later on to restore the default colour.

Only disadvantage here is that unless the last item in the series is hidden, the other lines will be recolored

like image 65
Jack Avatar answered Oct 19 '22 07:10

Jack


To hide a series in MSChart, use the Enabled property this way :

msChart.Series["Series"].Enabled = false;

and to show it again :

msChart.Series["Series"].Enabled = true;

So you dont need to remove points and re-add them.

like image 20
Larry Avatar answered Oct 19 '22 07:10

Larry