Page 1 of 1

TeeChart Newbie Q2 of 1022 ClickSeries event & Series Index

Posted: Fri Jul 02, 2010 6:26 am
by 8751509
Greetings,

When using the Click_Series Event how can you determine what the index of the series is that is under the mouse.

i.e. TeeChart.Series[n] ... what is n ...

Right now I am using the series name and then iterating through the series collection until the name matches counting all the way .. and thats how I get my 'n' ...

Is there a better way ?

Re: TeeChart Newbie Q2 of 1022 ClickSeries event & Series Index

Posted: Fri Jul 02, 2010 11:48 am
by 10050769
Hello Snarkle,

If you are using TChart1.SeriesClick Event you could use its parameters: series, valueindex, and MouseEvent.
I propose simple code that I think you can use in your project.

Code: Select all

public Form1()
        {

            InitializeComponent();
            InitializeChart();

        }
        private void InitializeChart()
        {

            Steema.TeeChart.Styles.Line line1 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
            line1.FillSampleValues();
            tChart1.ClickSeries += new Steema.TeeChart.TChart.SeriesEventHandler(tChart1_ClickSeries);

        }

        void tChart1_ClickSeries(object sender, Steema.TeeChart.Styles.Series s, int valueIndex, MouseEventArgs e)
        {
            this.Text = s[valueIndex].X.ToString();
        }
Could you please, check if previous code works as you want?

I hope will helps.

Thanks,

Re: TeeChart Newbie Q2 of 1022 ClickSeries event & Series Index

Posted: Mon Jul 05, 2010 12:59 am
by 8751509
Thanks for the reply Sandra ...

My Bad I wasn't very clear in my email .. this is what I am currently doing to find the index of a series.

Code: Select all

        
private void StockChart_ClickSeries(object sender, Steema.TeeChart.Styles.Series s, int valueIndex, MouseEventArgs e)
        {
            Series tmpSeries = (Series)s;
            SelectedSeriesX = tmpSeries.Title;

            /// todo - Temp until I find a better method to find Series index.
            int count = 0;
            foreach (Series ss in StockChart.Series)
            {
                if (ss.Title == SelectedSeriesX) 
                    SeriesIndex = count;
                
                ss.Color = Color.Black;
                count++;
            }

            tmpSeries.Color = Color.Red;
        }

The idea is that after clicking on a series (apart from the coloring stuff) in the variable 'SeriesIndex' I have the index of the Series under the mouse, so in another part of the code I can use a call such as StockChart.Series[SeriesIndex].Title = "Selected Series" (amongst other calls I wish to make);

The above code will do that as long as I dont get double ups in the series title (which sadly can happen) and looping through the series on every click will probably turn out to be most inefficient once I start having many more series in the chart.

Cheers Phil.

Re: TeeChart Newbie Q2 of 1022 ClickSeries event & Series Index

Posted: Mon Jul 05, 2010 9:07 am
by 10050769
Hello Phil,

Ok. I have made a simple code that I think that you can help you. Please, see next code and check if it works as you want:

Code: Select all

          private void InitializeChart()
    {
      tChart1.Aspect.View3D = false;

      for (int i = 0; i < 5; i++)
      {
        (tChart1.Series.Add(new Steema.TeeChart.Styles.Line())).FillSampleValues();
      }

      tChart1.ClickSeries += new Steema.TeeChart.TChart.SeriesEventHandler(tChart1_ClickSeries);
    }

    private int SeriesIndex;

    void tChart1_ClickSeries(object sender, Steema.TeeChart.Styles.Series s, int valueIndex, MouseEventArgs e)
    {
      SeriesIndex = tChart1.Series.IndexOf(s);

      for (int i = 0; i < tChart1.Series.Count; i++)
      {
        tChart1[i].Color = (i == SeriesIndex) ? Color.Red : Color.Black;
      }
    }
I hope will helps.

Thanks,

Re: TeeChart Newbie Q2 of 1022 ClickSeries event & Series Index

Posted: Mon Jul 05, 2010 11:17 pm
by 8751509
AHA ...

SeriesIndex = tChart1.Series.IndexOf(s);

Thats the ticket !!!... thanks ...