Page 1 of 1

Need event to fire when series visibility changes

Posted: Fri Jul 08, 2011 8:27 pm
by 13052841
Hi, I have a chart with 4 series that represents 2 different types of data (ie. both data values have a Line series and an Area series that display the same x,y coordinates):

Image

Since I do not need to display both the Following Error LINE and Following Error AREA series, I would like to automatically uncheck one when the other is checked. Is this possible? I thought about handling a "Series Visible" event and just unchecking the other series inside this event.

Thanks,
Kevin

Re: Need event to fire when series visibility changes

Posted: Mon Jul 11, 2011 11:52 am
by 10050769
Hello Kevin,
I have made a simple code when you unchecked or checked checkbox of Legend, disable the series in my case of same type and I recommend you do something us next code:

Code: Select all

 public Form1()
        {
            InitializeComponent();
            tChart1.Aspect.View3D = false;
            InitializeChart();
        }
        int index = 1;
        private void InitializeChart()
        {
            Steema.TeeChart.Styles.Line line = new Steema.TeeChart.Styles.Line(tChart1.Chart);
            Steema.TeeChart.Styles.Area area = new Steema.TeeChart.Styles.Area(tChart1.Chart);
            Steema.TeeChart.Styles.Line line1 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
            Steema.TeeChart.Styles.Area area1 = new Steema.TeeChart.Styles.Area(tChart1.Chart);

            line.FillSampleValues();
            line1.FillSampleValues();
            area.DataSource = line;
            area1.DataSource = line1;
            area.Color = Color.Transparent;
            area.AreaLines.Visible = false;
            area.Stairs = true;
            area1.Color = Color.Transparent;
            area1.AreaLines.Visible = false;
            area1.Stairs = true;
            tChart1.Legend.CheckBoxes = true;
            tChart1.ClickLegend += new MouseEventHandler(tChart1_ClickLegend);
        }

        void tChart1_ClickLegend(object sender, MouseEventArgs e)
        {
                
            if(index==1)
            {
                //Lines
                if(!tChart1[0].Visible && tChart1[2].Visible)
                {
                    tChart1[2].Visible=false;
                }
                else if(!tChart1[2].Visible && tChart1[0].Visible)
                {
                    tChart1[0].Visible=false;
                }
                //Areas
                if (!tChart1[1].Visible && tChart1[3].Visible)
                {
                    tChart1[3].Visible = false;
                }
                else if (!tChart1[3].Visible && tChart1[1].Visible)
                {
                    tChart1[1].Visible = false;
                }

             index++;//IndexControlClicks
            }
            else
            {
                //Lines
                if(!tChart1[0].Visible && tChart1[2].Visible)
                {
                    tChart1[0].Visible=true;
                }
                else if(!tChart1[2].Visible && tChart1[0].Visible)
                {
                    tChart1[2].Visible=true;
                }
                //Areas

                if (!tChart1[1].Visible && tChart1[3].Visible)
                {
                    tChart1[1].Visible = true;
                }
                else if (!tChart1[3].Visible && tChart1[1].Visible)
                {
                    tChart1[3].Visible = true;
                }
                index = 1;//IndexControll clicks
            }
Could you please, confirm us if previous code works as you expected?

I hope will helps.

Thank,

Re: Need event to fire when series visibility changes

Posted: Thu Jul 14, 2011 9:58 pm
by 13052841
Thanks. I tested the code and it worked okay however it did not allow me to make the series visible after clicking them off. This is not a problem though because I worked from your code and made mine work. The biggest thing was learning about the ClickLegend event.

Next question: Is it possible to know what item the user clicks within the Legend? Currently, I just toggle between Area and Line for all Series, but I would love to be able to only toggle the group of similar series that the user clicks on.

Thanks

Re: Need event to fire when series visibility changes

Posted: Fri Jul 15, 2011 7:55 am
by narcis
Hi LibDundas,
Next question: Is it possible to know what item the user clicks within the Legend? Currently, I just toggle between Area and Line for all Series, but I would love to be able to only toggle the group of similar series that the user clicks on.
Yes, this possible using Legend's Clicked method as in the example Yeray posted here.

To identify series types you might be interested in the example I posted here.

Hope this helps!

Re: Need event to fire when series visibility changes

Posted: Mon Jul 18, 2011 9:48 pm
by 13052841
Hi NarcĂ­s, that worked perfectly.

Thank you very much!