Page 1 of 1

How do I the Y-value of a Series when I know the X value?

Posted: Tue Feb 17, 2009 4:32 pm
by 13050364
Ive a chart that displays a line.

Im using a vertical cursor (set up so it follows the mouse). I can read the x-coord by doing;

double x = mainCursor.XValue;

If I read the y-value by doing

double x = mainCursor.XValue;

then Im just getting the mouse y-coord. I want the y-coord of the line. Is there an easy way to do this. Im assuming there is a function that I can call by passing the x-coord.

One way Ive thought of doing it is this;

int X;
double Y = theChart.Series[0].YValues[X];

The problem is I know the x-coord But I dont know the x index value.

Is there a simple solution here? Thanks.

Posted: Tue Feb 17, 2009 4:56 pm
by narcis
Hi Dave,

I can think of 2 options here:

1. Setting CursorTool to Snap=True, for example:

Code: Select all

    TChart1.Tools.Items(0).asTeeCursor.Snap = True
2. Use the interpolation example I posted here:

http://www.teechart.net/support/viewtopic.php?t=4161

Posted: Wed Feb 18, 2009 9:01 am
by narcis
Hi Dave,

Reading this thread I assume you are using TeeChart for .NET because of the syntax used. In which case you can find the interpolating example at All Features\Welcome !\Chart styles\Standard\Line(Strip)\Interpolating line series in the features demo available at TeeChart's program group.

Posted: Wed Feb 18, 2009 9:02 am
by 13050364
Narcis

Thanks. Im using;

mainCursor.SnapToPoint();

where

mainCursor = new Steema.TeeChart.Tools.CursorTool(theChart.Chart);


However Ive probably not described the question very well. I have a chart that displays a line (something like a share price graph) and I have added the vertical cursor. So when I drag the mouse left or right I control the vertical cursor line. What Im trying to get is the Yvalue of the point where the vertical cursor line intersects the share price graph line.

Im not interested in intermediate values (between points) so Ive set the snaptopoint() function.

Ive tried to do it (as described in the initial post) but Im guessing Im making it more complicated that it really is. I suspect there could be a single function call I could use?