Page 1 of 1
Interpolation/extrapolation using ActiveX TeeChart component
Posted: Wed Apr 20, 2005 2:32 pm
by 6919168
Does anyone know if there is a way to find the y coordinate for a given x coordinate for an XY series when there isn't a matching x coordinate in the series?
eg If a series contains points (2, 10), (4, 30), (9, 42.56), (10.2, 24.1)...
... is there a way to get the y coordinate when x=7 without having to perform my own interpolation?
I know that it seems as if I'm being lazy, but there is a performance issue when I calculate it myself and I am hoping there is a more efficient built-in method to interpolate (and/or extrapolate).
Thanks in advance,
Richard
Posted: Thu Apr 21, 2005 10:32 am
by narcis
Hi Richard,
You can do it using a vertical cursor tool and implementing it's OnChange event:
Code: Select all
Private Sub Form_Load()
TChart1.Series(0).FillSampleValues 10
TChart1.Tools.Items(0).asTeeCursor.Style = cssVertical
End Sub
Private Sub TChart1_OnCursorToolChange(ByVal Tool As Long, ByVal X As Long, ByVal Y As Long, ByVal XVal As Double, ByVal YVal As Double, ByVal Series As Long, ByVal ValueIndex As Long)
Dim ValuesStr As String
ValuesStr = "X: " + CStr(TChart1.Tools.Items(0).asTeeCursor.XVal) _
+ ", Y: " + CStr(TChart1.Tools.Items(0).asTeeCursor.YVal)
TChart1.Header.Text.Clear
TChart1.Header.Text.Add (ValuesStr)
End Sub
Posted: Mon Apr 25, 2005 1:10 pm
by 6919168
Hi Narcis,
I tried your code and found that moving the vertical cursor only changes the x axis value - the y axis value never changes. (I also notice that if both horizontal and vertical are enabled, changing the y value doesn't report the correspondig x value either.)
In my program I want to programmatically iterate through each x value in one series and find what the corresponding y value on another series is for the same x value.
Re: Interpolation/extrapolation using ActiveX TeeChart compo
Posted: Mon Apr 25, 2005 3:41 pm
by Marjan
6919168 wrote:... is there a way to get the y coordinate when x=7 without having to perform my own interpolation?
I think not. You'll have to calculate local linear approximate and then use it for calculating y=y(x). It's not that complication + it really doesn't take heavy tool on cpu <gg>. I did an example for Delphi, but the same approach can be used for AX or .NET version. A discusion can be found
here.
Posted: Mon Apr 25, 2005 3:50 pm
by 6919168
The reason I was hoping to avoid doing the linear interpolation is that I have sporradic data going back to 1976 and finding the closest point prior to the intersection could be quite time consuming. However, where needs must.....
Thank you all for the help.
Ritchie
Posted: Tue Apr 26, 2005 12:44 pm
by Marjan
Hi.
have sporradic data going back to 1976
Ok, the number of points can slow down the search for closest points. But there is no need to search all points - you can do a left/right search once you have initial reference point (since x values are already sorted).
Posted: Wed Apr 27, 2005 1:38 pm
by 6919168
Just thinking....My data source is via ADO and I can run a quick query to find the 1st date in my second curve (ie the one I want to get the y value from) which comes after the seek date, and then use a vertical cursor attached to the 2nd curve to get the index and y2 value, and hence the date at the previous index and the y1 value - Problem solved !
Thanks again
Ritchie