Page 1 of 1

How to retrieve the data from the datagrid

Posted: Wed Jun 08, 2005 2:32 pm
by 9524808
Hi,

Please is there any method to retrieve data from the "data" tab, inside the charteditor.
Since I have series inside a Tchart with different count (length), I don't see another solution to get the 'Y' data of all series on a certain X.
One serie thus start with X=1, another with X=15, another with X=42 and so on.

What do you recommend me to do please?

Posted: Thu Jun 09, 2005 1:54 pm
by narcis
Hi,

At the TeeChart features demo you'll find a couple of examples regarding Chart Grid. You'll find that demo at the TeeChart program group. Browse All Features\ Welcome!\ Components\Chart Grid.
What do you recommend me to do please?
I don't understand very much what are you trying to do. Could you please be more specific?

Posted: Fri Jun 10, 2005 9:47 am
by 9524808
I'm sorry I wasn't clear enough.

I am unable to get the data from every serie on a certain X position.
As a sample I take the achieved data from the crosshairs.

None of the following methods gives met the Y value of a serie on a certain X position :
Tchartv2.Series(0).PointValue
Tchartv2.Series(0).CalcYPos(x)
Tchartv2.Series(0).CalcYPosValue(x)
Tchartv2.Series(0).YScreenToValue(x)
Tchartv2.Series(0).YValues.Value(x)


I used to work with pointvalue :
For i = 0 To TchartV2.SeriesCount - 1
strAnnotation = strAnnotation + Chr$(13) + left$(TchartV2.Series(i).Name, 3) + ":" + Format$(TchartV2.Series(i).PointValue(nValue), "##.###0")
Next
TchartV2.Tools.Items(TL_ANNOTATE).asAnnotation.text = strAnnotation

Which were fine till a new problem arised.
Not every serie has the same number of points.
We have on a Tchart data with 250 entries, 230, 210 and so on.

Therefore I hoped to retrieve the data from the datagrid where you can clearly notice the Y value on a certain X position.
With the datagrid I mean the data tab inside the charteditor and not the extra datagrid component.

I continue with a sample from the datagrid.
If we take #0 we have X=1
Bar_0 : Y = 17.93
Serie0 : Y = -
Serie1 : Y = -
Serie2 : Y = 17.8
If we take #8 we have X=9 (first point of serie 0)
Bar_0 : Y = 18.08
Serie0 : Y = 17.96
Serie1 : Y = -
Serie2 : Y = 17.57
If we take #25 we have X=26 (first point of serie 1)
Bar_0 : Y = 17.8
Serie0 : Y = 17.82
Serie1 : Y = 17.96
Serie2 : Y = 17.45
Above data is correct and can be seen in the datagrid.

Now, when I use ...pointvalue(1) then I have:
Bar_0 : Y = 17.93
Serie0 : Y = 17.96
Serie1 : Y = 17.96
Serie2 : Y = 17.8
which is not correct on serie0 and serie1 since those series do not start on point 1.

So with which command can we retrieve for example the data on X=26
Bar_0 : Y = 17.8
Serie0 : Y = 17.82
Serie1 : Y = 17.96
Serie2 : Y = 17.45

I hope this helps. :(
[/url]

Posted: Fri Jun 10, 2005 2:25 pm
by narcis
Hi Bush,

If you want to have all series Y values for a given X value you can interpolate through series doing something like the code below. This example uses a CursorTool, however you can use InterpolateLineSeries passing a fix value to XValue parameter.

Code: Select all

Function InterpolateLineSeries(ByVal SeriesIndex As Long, FirstIndex As Integer, LastIndex As Integer, XValue As Double) As Double
  Dim index As Integer
  Dim dx, dy, val As Double

  index = FirstIndex

  Do While ((TChart1.Series(SeriesIndex).XValues.Value(index) <= XValue) And (index < LastIndex))
    index = index + 1
  Loop
  
  ' safeguard
  If (index < 1) Then
    index = 1
  ElseIf (index >= TChart1.Series(SeriesIndex).Count) Then
    index = TChart1.Series(SeriesIndex).Count - 1
  End If
  
  ' y=(y2-y1)/(x2-x1)*(x-x1)+y1
  dx = TChart1.Series(SeriesIndex).XValues.Value(index) - TChart1.Series(SeriesIndex).XValues.Value(index - 1)
  dy = TChart1.Series(SeriesIndex).YValues.Value(index) - TChart1.Series(SeriesIndex).YValues.Value(index - 1)
  
  If (dx <> 0) Then
    InterpolateLineSeries = dy * (XValue - TChart1.Series(SeriesIndex).XValues.Value(index - 1)) / dx + TChart1.Series(SeriesIndex).YValues.Value(index - 1)
  Else
    InterpolateLineSeries = 0
  End If
End Function

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)
    TChart1.Header.Text.Clear
    For i = 0 To TChart1.SeriesCount - 1
        TChart1.Header.Text.Add ("Series" + CStr(i) + ": Y(" + CStr(XVal) + ")= " + _
                CStr(InterpolateLineSeries(i, 0, TChart1.Series(i).Count - 1, XVal)))
    Next
End Sub

Posted: Sat Jun 11, 2005 3:31 pm
by 9524808
What a splendid function!
Mny thx Narcis. :D