Page 1 of 1

Operation between series that don't have the same X Values

Posted: Thu Oct 28, 2004 12:33 pm
by 9524648
HI !
I've been using the Teechart ActiveX to display several different measures (Power, hygrometry, Current...) which are captured depending on the time.
The problem is that the acquisition frequency for each channel is different so that X Colums for each channel contains different values (X colums contain the acquisition time values). ie : X_Curent =1,2,3,4,5,6,7,8... , X_power=1,1.5,2,2.5,3,3.5,....
Now I want, for example, add the measures of power and current which corresponds to the same time, that is Y_Current(X_Current==1)+Y_Power(X_Power==1), Y_current(X_Current==2)+Y_power(X_Power==2), and so on. The rersults must be placed in a new xy serie.
I've planned to use the add method for the result serie and to set its datasource as current and power series.
The problem is that those functions work with series index isn't it ?
I will get Y_Current(X_Current==1)+Y_Power(X_Power==1), Y_current(X_Current==2)+Y_power(X_Power==1.5), ,...
I don't know if what i want to do is possible with the teechart activeX in few lines of code...
Any Idea ?

Posted: Fri Oct 29, 2004 11:01 am
by Pep
Hi,

to do this you can create custom functions. Please find following a code example of how to use either a TChart function or a custom function to calculate the Average of a series:

Code: Select all

Private Sub Command1_Click()
With TChart1
    If .SeriesCount > 1 Then
        .RemoveSeries 1
    End If
    .AddSeries scLine
    .Series(1).SetFunction tfAverage
    .Series(1).DataSource = "Series0"
    .Series(1).CheckDataSource
End With
End Sub

Private Sub Command2_Click()
Dim MyAverage As Double
With TChart1
    If .SeriesCount > 1 Then
        .RemoveSeries 1
    End If
    For i = 0 To .Series(0).Count - 1
        MyAverage = MyAverage + .Series(0).YValues.Value(i)
    Next i
    MyAverage = MyAverage / .Series(0).Count
    .AddSeries scLine
    For i = 0 To .Series(0).Count - 1
        .Series(1).AddXY .Series(0).XValues.Value(i), MyAverage, "",
clTeeColor
    Next i
End With
End Sub

Private Sub Form_Load()
With TChart1
    .AddSeries scBar
    .Series(0).FillSampleValues 20
    .Series(0).Marks.Visible = False
    .Legend.Visible = False
End With
End Sub

Posted: Thu Feb 10, 2005 2:44 pm
by 9524648
Yes. It works if ther is only one serie as input but not if there are more.
ex :
Serie0
XValues = 0 , 1 , 2 , 3 , 4 , 5
YValues = a , b , c , d , e , f (integers)

Serie1
XValues = 0 , 0.5 , 1 , 1.5 , 2 , 2.5
YValues = A , B , C , D , E , F (other integers)

Now I want to create a result serie whose values must be :
XValues = 0 , 1 , 2
YValues = a+A , b+C , c+E (add y values of both input series for points which have the same X co-ordinate)


In fact the problem is that the input series can have different number of points and that their x_values are not necessarily equal.

It's difficult to explain as english is not my mother's tongue... :D
I hope you understand me and I'm waiting your reply.
Thanks a lot.

Posted: Thu Feb 10, 2005 3:24 pm
by narcis
Hi tdm,

Ok, then you can do something like this:

Code: Select all

Private Sub Form_Load()
    Dim i, j As Integer
    
    With TChart1
      'Add 2 data Series
      .AddSeries scBar
      .AddSeries scBar
      .Series(0).Marks.Visible = False
      .Series(1).Marks.Visible = False
      
      ' Populate them with random data
      For i = 0 To 9
        .Series(0).AddXY Rnd(100), Rnd(100), "", clTeeColor
      Next
      
      For j = 0 To 14
        .Series(1).AddXY Rnd(100), Rnd(100), "", clTeeColor
      Next
      
      ' Add a series to be used for an Average Function
      .AddSeries scLine
      'Define the Function Type for the new Series
      .Series(2).SetFunction tfAverage
      'Define the Datasource for the new Function Series
      'Datasource accepts the Series titles of the other 2 Series
      .Series(2).DataSource = "Series0,Series1"
       '    *Note - When populating your input Series manually you will need to
       '    use the Checkdatasource method
    End With
End Sub

Posted: Thu Feb 10, 2005 4:07 pm
by 9524648
no, no.
In your example, the input series have the same X values. They are x-synchronized.
Mines are not.
For the moment, my algorith is the following :
Take the first x_value of the first serie
Search this value or the closest x-value in the x-values of the second serie.
Take the y value associated with the x_value of the first serie.
Take the y value associated with the x_value found in the second serie
Add these two y_values.
Pass to the next x_value in the first serie and searh a corresponding x_value in the second serie. Take the y_values corresppnding to these two x_values and add them.
etc...