Page 1 of 1

How do I read first series selected from legend checkboxes?

Posted: Mon May 06, 2013 10:39 am
by 13050364
Hi

If there are say 10 series on the chart and there is checkboxes on the chart legend to allow selection of each one how do I get the first selected series (ie. the first series with the checkbox checked).We are using TeeChart version 3.5.3187.15585 and C#.NET

Thanks

Re: How do I read first series selected from legend checkboxes?

Posted: Mon May 06, 2013 3:27 pm
by 10050769
Hello Dave,

I have made a simple code that I think help you to achieve as you want:

Code: Select all

public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }
        Steema.TeeChart.Styles.FastLine line1, line2, line3, line4;
        private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;
            line1 = new FastLine(tChart1.Chart);
            line2 = new FastLine(tChart1.Chart);
            line3 = new FastLine(tChart1.Chart);
            line4 = new FastLine(tChart1.Chart);
            line1.FillSampleValues();
            line2.FillSampleValues();
            line3.FillSampleValues();
            line4.FillSampleValues();

            tChart1.Legend.CheckBoxes = true;
            tChart1.ClickLegend += new MouseEventHandler(tChart1_ClickLegend);
            tChart1.Draw();
        }
        bool isFirstVisible; 
        int index;
        void tChart1_ClickLegend(object sender, MouseEventArgs e)
        {
            index = 0;
            isFirstVisible = false;
            while(index<tChart1.Series.Count && !isFirstVisible)
            {
                if (tChart1[index].Active)
                {
                    isFirstVisible = true; 
                }
                else
                {
                    isFirstVisible = false; 
                    index++; 
                }
            }
            if (isFirstVisible)
            {
                this.Text = tChart1[index].Title; 
            }
        }
Could you tell us if previous code works as you want?

Thanks,