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
Usage of standard deviation function
Re: Usage of standard deviation function
Hi Hari,
Here it is an example that I think achieves what you described:
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,
![]() | Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) |
![]() ![]() ![]() ![]() ![]() ![]() |
Please read our Bug Fixing Policy |
Re: Usage of standard deviation function
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
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
Re: Usage of standard deviation function
Hi Hari,
The example above gives me the following result: 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:
The example above gives me the following result: 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,
![]() | Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) |
![]() ![]() ![]() ![]() ![]() ![]() |
Please read our Bug Fixing Policy |
Re: Usage of standard deviation function
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
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
Re: Usage of standard deviation function
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:
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:
I've added it to the wish list to be revised for future releases (TV52015063).
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)
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);
Best Regards,
![]() | Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) |
![]() ![]() ![]() ![]() ![]() ![]() |
Please read our Bug Fixing Policy |
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Re: Usage of standard deviation function
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.
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 |
![]() ![]() ![]() ![]() ![]() ![]() |
Instructions - How to post in this forum |