Need event to fire when series visibility changes

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
LibDundas
Newbie
Newbie
Posts: 55
Joined: Fri Mar 20, 2009 12:00 am

Need event to fire when series visibility changes

Post by LibDundas » Fri Jul 08, 2011 8:27 pm

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

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Need event to fire when series visibility changes

Post by Sandra » Mon Jul 11, 2011 11:52 am

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,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

LibDundas
Newbie
Newbie
Posts: 55
Joined: Fri Mar 20, 2009 12:00 am

Re: Need event to fire when series visibility changes

Post by LibDundas » Thu Jul 14, 2011 9:58 pm

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

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Need event to fire when series visibility changes

Post by Narcís » Fri Jul 15, 2011 7:55 am

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!
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

LibDundas
Newbie
Newbie
Posts: 55
Joined: Fri Mar 20, 2009 12:00 am

Re: Need event to fire when series visibility changes

Post by LibDundas » Mon Jul 18, 2011 9:48 pm

Hi Narcís, that worked perfectly.

Thank you very much!

Post Reply