How Do I get the Y value of a series (cursor tool intersect)

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Dave
Advanced
Posts: 139
Joined: Mon Sep 22, 2008 12:00 am

How Do I get the Y value of a series (cursor tool intersect)

Post by Dave » Tue Mar 03, 2009 9:10 am

Hello

Im a beginner as regards programming the Steema charts. Im trying to get the point of intersection of a vertical line (Cursor Tool) and a Series on a TeeChart. Im looking for the Y-value of the Series (not a screen co-ord)

Im developing a Windows application in Visual C#.

Ive added a TeeChart to a form. Its called Chart1

In the windows form constructor Ive the following code:

Chart1.Series.Add(Voltages);
mainCursor = new Steema.TeeChart.Tools.CursorTool(Chart1);

mainCursor.FollowMouse = true;
mainCursor.Style =Steema.TeeChart.Tools.CursorToolStyles.Vertical;
mainCursor.Pen.Width = 1;
mainCursor.Pen.Color = Color.Red;
mainCursor.Pen.Style = System.Drawing.Drawing2D.DashStyle.Dash;

mainCursor.Change += new CursorChangeEventHandler(mainCursor_Change);


Then in the Cursor change event:

void mainCursor_Change(object sender, CursorChangeEventArgs e) {

mainCursor.Series = voltageLines;
mainCursor.SnapToPoint();

}


If I add the following to the mainCursor_Change event:

double x1 = mainCursor.XValue;
double y1 = mainCursor.YValue;

then y1 is the value of the mouse position. Not the y-intersection of the Series which is what I want.

The way Im thinking it should be done is to somehow return an index based on the xposition of the Cursor Tool and then use this index to retreive the Y-value. But Im not sure how I do this. Any ideas? Thanks.

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

Post by Sandra » Tue Mar 03, 2009 11:17 am

I check that valueIndex not working properly.I have added to the list of Bug Report with number [TF02013917] we will try to fix it for next versions of TeeChart .NET.

You can use next code for get y-intersection values:

InitializeChart:

Code: Select all

        Steema.TeeChart.Styles.Line Voltages;
        Steema.TeeChart.Tools.CursorTool mainCursor;
        private void InitializeChart()
        {
                Voltages = new Steema.TeeChart.Styles.Line();
                tChart1.Series.Add(Voltages);
                Voltages.FillSampleValues(10);
                mainCursor = new Steema.TeeChart.Tools.CursorTool(tChart1.Chart);
                mainCursor.FollowMouse = true;
                mainCursor.Snap = true;
                mainCursor.Style = Steema.TeeChart.Tools.CursorToolStyles.Vertical;
                mainCursor.Series = Voltages;
                mainCursor.Pen.Width = 1;
                mainCursor.Pen.Color = Color.Red;
                mainCursor.Pen.Style = System.Drawing.Drawing2D.DashStyle.Dash;
                mainCursor.Change += new Steema.TeeChart.Tools.CursorChangeEventHandler(mainCursor_Change);

        }

MainCursor_Change Event:

Code: Select all

        void mainCursor_Change(object sender, Steema.TeeChart.Tools.CursorChangeEventArgs e)
        {
            double x1 = mainCursor.XValue;
            int tmp = e.Series.XValues.IndexOf(mainCursor.XValue);
            double y1 = e.Series.YValues[tmp];
            this.Text = "Y=" + Convert.ToString(Convert.ToInt32(y1)) + " X= " + Convert.ToString(Convert.ToInt32(x1));//see values
        }
I hope that my help you serve
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

Dave
Advanced
Posts: 139
Joined: Mon Sep 22, 2008 12:00 am

Post by Dave » Mon Mar 16, 2009 11:32 am

Thankyou Sandra. That has solved my problem. cheers.

Post Reply