function issues

TeeChart for ActiveX, COM and ASP
Post Reply
mpaulson
Newbie
Newbie
Posts: 41
Joined: Fri Nov 15, 2002 12:00 am

function issues

Post by mpaulson » Sun Apr 13, 2008 2:55 pm

Hi:

I'm working with functions. I've implemented many of them, but some work and some do not. My basic subroutine to enable a function is:

Private Sub SetUnSetFunction(Mnu As Menu, SeriesType As Long, Label As String)

With TChart1(TChartIndex)

Do While .SeriesCount > 1
.RemoveSeries .SeriesCount - 1
Loop

If Mnu Is FunctionMenu Then
Set FunctionMenu = Nothing
Exit Sub
End If

Set FunctionMenu = Mnu
Mnu.Checked = True

SeriesNum = 1

.AddSeries scLine
.Series(SeriesNum).SetFunction SeriesType
.Series(SeriesNum).Title = Label
.Series(SeriesNum).DataSource = .Series(0).Name
.Series(SeriesNum).CheckDataSource

End With
end sub

And it it's called as:

SetUnSetFunction MnuAverage, tfAverage, "Average"

The functions that work are:

Average
Exp Trend
Median
Perimeter
RMS
Smoothing
Std. Dev.
Trend

The functions that don't work are:

Correlation
Mode
Momentum division
Performance
Variance

For the functions that don't work, in general the new function series is all 0, but sometimes adding the function series forces both series' to 0.

Am I doing something wrong?

Thanks,

Matt

Yeray
Site Admin
Site Admin
Posts: 9611
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Post by Yeray » Mon Apr 14, 2008 9:31 am

Hi Matt,

I've tested the functions, and looking at the new features demo to see if they do what expected, and they seem to work fine.

But note that some functions calculate percentages and other values really lower than source values and maybe that's why they seem to be 0. And that's why I've set the right axis to the functions' vertical axis.

Here is the code I've used:

Code: Select all

Private Sub Combo1_Change()
  With TChart1
    Do While .SeriesCount > 1
      .RemoveSeries .SeriesCount - 1
    Loop
    
    Select Case Combo1.ListIndex
      Case 0:
      Case 1: .AddSeries scLine
              .Series(1).SetFunction tfAverage
      Case 2: .AddSeries scLine
              .Series(1).SetFunction tfExpTrend
      Case 3: .AddSeries scLine
              .Series(1).SetFunction tfMedian
      Case 4: .AddSeries scLine
              .Series(1).SetFunction tfPerimeter
      Case 5: .AddSeries scLine
              .Series(1).SetFunction tfRMS
      Case 6: .AddSeries scLine
              .Series(1).SetFunction tfSmoothing
      Case 7: .AddSeries scLine
              .Series(1).SetFunction tfStdDeviation
      Case 8: .AddSeries scLine
              .Series(1).SetFunction tfTrend
      Case 9: .AddSeries scLine
              .Series(1).SetFunction tfCorrelation
      Case 10: .AddSeries scLine
               .Series(1).SetFunction tfMode
      Case 11: .AddSeries scLine
               .Series(1).SetFunction tfMomentumDiv
      Case 12: .AddSeries scLine
               .Series(1).SetFunction tfPerformance
      Case 13: .AddSeries scLine
               .Series(1).SetFunction tfVariance
    End Select
    
    If Combo1.ListIndex <> 0 Then
      .Series(1).Title = "My function"
      .Series(1).DataSource = .Series(0).Name
      .Series(1).CheckDataSource
      .Series(1).VerticalAxis = aRightAxis
    End If
  End With
End Sub

Private Sub Combo1_Click()
  Combo1_Change
End Sub

Private Sub Form_Load()
Dim i As Integer
  TChart1.AddSeries scPoint
  
  For i = 0 To 100
    TChart1.Series(0).Add (Rnd()), "", clTeeColor
  Next i
    
  Combo1.AddItem "No functions", 0
  Combo1.AddItem "Average", 1
  Combo1.AddItem "Exp Trend", 2
  Combo1.AddItem "Median", 3
  Combo1.AddItem "Perimeter", 4
  Combo1.AddItem "RMS", 5
  Combo1.AddItem "Smoothing", 6
  Combo1.AddItem "Std. Dev.", 7
  Combo1.AddItem "Trend", 8
  Combo1.AddItem "Correlation", 9
  Combo1.AddItem "Mode", 10
  Combo1.AddItem "Momentum division", 11
  Combo1.AddItem "Performance", 12
  Combo1.AddItem "Variance", 13
  Combo1.ListIndex = 0
End Sub
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

mpaulson
Newbie
Newbie
Posts: 41
Joined: Fri Nov 15, 2002 12:00 am

Post by mpaulson » Mon Apr 14, 2008 12:03 pm

Hi:

I see your point about scaling and the right axis. Now I get at least something > (apparent) 0 for each function I try.

I will note that you are appearing to calculate the mode as the smallest number in the set when there are no repeating values. I'm not a stats expert, but it seems to me that this should be either "undefined" or "0".

Thanks,

Matt

Yeray
Site Admin
Site Admin
Posts: 9611
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Post by Yeray » Tue Apr 15, 2008 8:09 am

Hi Matt,

In mathworks website, in the mode function description they say:

"When there are multiple values occurring equally frequently, mode returns the smallest of those values"

So, I suppose that when you have no repeated value, all frequencies are 0, and the smallest value of the series should be returned.

But I'm not an expert on statistics either, so I'll ask for another opinion.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Yeray
Site Admin
Site Admin
Posts: 9611
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Post by Yeray » Thu Apr 17, 2008 8:00 am

Hi Matt,

When you have a source without repeated values, one should expect to have a NAN (Not A Number) return for mode function.

So, the best approach is to check series data if it makes sense to apply mode function before you pass it to the function.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply