TTrendFunction Calculation Error
Posted: Tue Jul 06, 2004 9:18 am
TeeChart Version 7 & Delphi 7:
You have an issue with the TTrendFucntion when one of the point is zero.
I am using a TPointSeries and TLineSeries to draw a calibration line.
1st point: 0 , 1.06207
2nd point:1 , 672.42340
and this is the section of code that calls the TTrendFunction
with MyLineSeries do begin
DataSources.Clear;
DataSources.Add( MyPointSeries );
SetFunction( TTrendFunction.Create(Self) );
{display trend line}
CheckDataSource;
X1 := XValue[0];
X2 := XValue[1];
Y1 := YValue[0];
Y2 := YValue[1];
end;
Now what you will notice that the value of YValue[0] changes somehow to double the value of 1.06207. The error is less notisable when you have more than 2 points and it only happens when you have a zero as one of the points.
X1, X2, Y1, Y2 are used to calculate the slope and the Y intercept
Slope:= (Y2 - Y1)/(X2 - X1);
YIntercept := Y1 - X1 * (Y2 - Y1) / (X2 - X1) ;
Using the values above after the line has been ploted the YIntercept was calculated to be 2.124 where it should have been = to 1.06207.
I have checked TeeChart Version 4 & Delphi 5 and the calculations are correct.
Any ideas?
Regards,
Slim
You have an issue with the TTrendFucntion when one of the point is zero.
I am using a TPointSeries and TLineSeries to draw a calibration line.
1st point: 0 , 1.06207
2nd point:1 , 672.42340
and this is the section of code that calls the TTrendFunction
with MyLineSeries do begin
DataSources.Clear;
DataSources.Add( MyPointSeries );
SetFunction( TTrendFunction.Create(Self) );
{display trend line}
CheckDataSource;
X1 := XValue[0];
X2 := XValue[1];
Y1 := YValue[0];
Y2 := YValue[1];
end;
Now what you will notice that the value of YValue[0] changes somehow to double the value of 1.06207. The error is less notisable when you have more than 2 points and it only happens when you have a zero as one of the points.
X1, X2, Y1, Y2 are used to calculate the slope and the Y intercept
Slope:= (Y2 - Y1)/(X2 - X1);
YIntercept := Y1 - X1 * (Y2 - Y1) / (X2 - X1) ;
Using the values above after the line has been ploted the YIntercept was calculated to be 2.124 where it should have been = to 1.06207.
I have checked TeeChart Version 4 & Delphi 5 and the calculations are correct.
Any ideas?
Regards,
Slim