How to get series y-axis value of user's Mouse Click.

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
biji
Newbie
Newbie
Posts: 35
Joined: Wed Jul 02, 2008 12:00 am

How to get series y-axis value of user's Mouse Click.

Post by biji » Tue Mar 15, 2016 9:39 am

Hi all,

I am trying to get y-axis values of several series when user mouse left click on chart. I am using TeeChart on my windows form application(c#)

I have tried like this

Code: Select all

   private void mainTChart_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                mainTChart.Axes.Bottom.CalcMinMax(ref minTime, ref maxTime);
                cdens = mainTChart.Series[0].XValues.IndexOf(e.X);
                cdens = mainTChart.Series[0].YValues.IndexOf(e.Y);
                cdens = mainTChart.Series[0].YValues.Value[Convert.ToInt16(e.Y)];
                //cvisc = mainTChart.Series[1].YScreenToValue(e.Y);
                cvisc = mainTChart.Series[1].YValues.Value[e.Y];
            }
}
I can see all y-values of corresponding series by using " Series[0].YValues.Value[];" . how to get the index value of mouse click. If i can get index value of mouse click the i can easily get the value!

Is there any other way to get y-values of mouse click?

I have tried several ways but i am not able to get values. I have gone through documentation as well but not found what i want to do.

Thanks in advance,

Regards,
biji.

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: How to get series y-axis value of user's Mouse Click.

Post by Christopher » Tue Mar 15, 2016 11:48 am

biji wrote: Is there any other way to get y-values of mouse click?
Yes, you can try code similar to the following:

Code: Select all

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

      for (int i = 0; i < 5; i++)
      {
        tChart1.Series.Add(typeof(Bar)).FillSampleValues();
      }
    }

    private void TChart1_ClickSeries(object sender, Series s, int valueIndex, MouseEventArgs e)
    {
      if(e.Button == MouseButtons.Right)
      {
        MessageBox.Show("YValue = " + s.YValues[valueIndex].ToString());
      }
    }
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Post Reply