Usage of standard deviation function

TeeChart for ActiveX, COM and ASP
Post Reply
Hari
Newbie
Newbie
Posts: 12
Joined: Wed Jun 09, 2010 12:00 am

Usage of standard deviation function

Post by Hari » Fri Jul 23, 2010 8:05 pm

I am using Activex v8 version of TeeChart.

I have a line series and i want to display the average and standard deviation for that series as a text (annotation tool).

I was able to use the "m_chart.Series(index).SetFunction(tfAverage)" to find the average. I then disabled this series and used "GetYValues().GetValue(value_index)" to obtain the average value in a local variable, which i then converted to string for display.

However, when i did the same thing to find the standard deviation, it always displayed "0.0" as the value. When i checked the TeeChart tutorial, it says that standard deviation function requires only one input.

Can someone please tell me how to find the standard deviation for a series?

Thanks,
Hari

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

Re: Usage of standard deviation function

Post by Yeray » Mon Jul 26, 2010 12:26 pm

Hi Hari,

Here it is an example that I think achieves what you described:

Code: Select all

Private Sub Form_Load()  
  With TChart1
    .Aspect.View3D = False
    .AddSeries scPoint
    .Series(0).FillSampleValues 5
  
    .AddSeries scLine
    .Series(1).SetFunction tfAverage
    .Series(1).DataSource = .Series(0)
    .Series(1).CheckDataSource
    .Tools.Add tcAnnotate
    With .Tools.Items(0).asAnnotation
      .Left = 10
      .Top = 10
      .Text = "Average: " + Str$(TChart1.Series(1).YValues.Value(0))
    End With
  
    .AddSeries scLine
    .Series(2).SetFunction tfStdDeviation
    .Series(2).DataSource = .Series(0)
    .Series(2).CheckDataSource
    .Tools.Add tcAnnotate
    With .Tools.Items(1).asAnnotation
      .Left = 150
      .Top = 10
      .Text = "Standard deviation: " + Str$(TChart1.Series(2).YValues.Value(0))
    End With
    
    TChart1.Series(1).Active = False
    TChart1.Series(2).Active = False
  End With
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

Hari
Newbie
Newbie
Posts: 12
Joined: Wed Jun 09, 2010 12:00 am

Re: Usage of standard deviation function

Post by Hari » Mon Jul 26, 2010 5:19 pm

Hi Yeray.

I already tried exactly what you said. It does not work for standard deviation. It displays the values as 0. However, the average function works fine.

As i mentioned earlier, the tutorial says that number of inputs for std. deviation is 1 and it is described as "Maps the Standard Deviation (or Complete Standard Deviation) of every group of Period points".

This doesn't make sense to me.

Hari

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

Re: Usage of standard deviation function

Post by Yeray » Tue Jul 27, 2010 8:56 am

Hi Hari,

The example above gives me the following result:
test.png
test.png (17.06 KiB) Viewed 7769 times
Doesn't it give the same result to you? What exact TeeChart version are you using? Is it the latest available in the client area?

Regarding to the number of inputs, I've seen that the following snipped of code works in the same way in both functions:

Code: Select all

    TChart1.Series(2).FunctionType.PeriodStyle = psNumPoints
    TChart1.Series(2).FunctionType.Period = 2
    TChart1.Series(2).asLine.Pointer.Visible = True
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

Hari
Newbie
Newbie
Posts: 12
Joined: Wed Jun 09, 2010 12:00 am

Re: Usage of standard deviation function

Post by Hari » Tue Jul 27, 2010 6:38 pm

Hi Yeray.

I am using the latest ActiveX version 8.

I guess i found out the problem. The problem is with the SetPeriod(). My line series has 61400 points. If i set the period for standard deviation to 61400 or 50000, it shows the value as 0. However if i set the period to say 30000, it displays 2 values for standard deviation, one for the first 30000 points and the other for the next 30000. If i set the period to 2, then i am getting 30700 values for standard deviation, one value for 2 consecutive points.

So is there some maximum limit for SetPeiod() function for standard deviation? It displays the correct value for standard deviation if i set the period to 45000. Changing the PeriodStyle does not affect the output.

However, the average function works fine if i set the period to 61400.

Hari

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

Re: Usage of standard deviation function

Post by Yeray » Fri Jul 30, 2010 4:14 pm

Hi Hari,

There is no limitation for the Period.
I've made some tests and found an strange behaviour. In the delphi sources, in the CalculateDeviation function, there is the following calculation:

Code: Select all

Divisor:=INumPoints*(INumPoints-1)
I don't understand why, when INumPoints has a value between 46342 and 65536, it gives an unexpected, negative value, and this makes the function to return a 0 when shouldn't.
We've also seen that creating an intermediate variable the problem seems to be solved:

Code: Select all

var tmp: Double;
begin
  tmp:=INumPoints;
  //...
  Divisor:=tmp*(tmp-1);
I've added it to the wish list to be revised for future releases (TV52015063).
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

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

Re: Usage of standard deviation function

Post by Narcís » Tue Sep 21, 2010 11:28 am

Hi Hari,

As an update, after some more investigation we found the solution Yeray suggested is the correct one as INumPoints needs to be type-casted to a double value so that Std. Deviation is calculated correctly. We implemented the fix for next maintenance release.
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

Post Reply