Interpolation/extrapolation using ActiveX TeeChart component

TeeChart for ActiveX, COM and ASP
Post Reply
Ritchie
Newbie
Newbie
Posts: 15
Joined: Mon May 21, 2001 4:00 am
Location: Scotland

Interpolation/extrapolation using ActiveX TeeChart component

Post by Ritchie » Wed Apr 20, 2005 2:32 pm

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

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Apr 21, 2005 10:32 am

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
Best Regards,
Narcís Calvet / 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

Ritchie
Newbie
Newbie
Posts: 15
Joined: Mon May 21, 2001 4:00 am
Location: Scotland

Post by Ritchie » Mon Apr 25, 2005 1:10 pm

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.

Marjan
Site Admin
Site Admin
Posts: 745
Joined: Fri Nov 07, 2003 5:00 am
Location: Slovenia
Contact:

Re: Interpolation/extrapolation using ActiveX TeeChart compo

Post by Marjan » Mon Apr 25, 2005 3:41 pm

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.
Marjan Slatinek,
http://www.steema.com

Ritchie
Newbie
Newbie
Posts: 15
Joined: Mon May 21, 2001 4:00 am
Location: Scotland

Post by Ritchie » Mon Apr 25, 2005 3:50 pm

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

Marjan
Site Admin
Site Admin
Posts: 745
Joined: Fri Nov 07, 2003 5:00 am
Location: Slovenia
Contact:

Post by Marjan » Tue Apr 26, 2005 12:44 pm

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).
Marjan Slatinek,
http://www.steema.com

Ritchie
Newbie
Newbie
Posts: 15
Joined: Mon May 21, 2001 4:00 am
Location: Scotland

Post by Ritchie » Wed Apr 27, 2005 1:38 pm

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

Post Reply