Cannot extrapolate TeeChart Trend Function

1.1k views Asked by At

I'm using teechart with delphi to plot a series and the trend line for that series using the following code:

TF:= TTrendFunction.Create(self);
TrendSeries.SetFunction(TF);
TrendSeries.DataSource := OrigSeries;
TrendSeries.CheckDataSource;

It works fine, but I was wondering if it's possible to have the trend line extrapolate forwards or backwards? I can't seem to find a way to retrieve x and y values of the series after it applies the function to extrapolate. I tried using the CalculateTrend function to calculate the 'm' and 'b' in y = mx + b, but it gave an access violation for that, same as when I try to access the series.YValue[i].

So is there even a way to retrieve those points it plots after applying the trend function?

Thanks.

2

There are 2 answers

0
Simon On

The trend line is based on the original data in the series, therefore, to extrapolate the trend line, you must provide more data to the original series.

0
David Berneda On

The Trend function adds 2 points to TrendSeries. Point 0 is at X minimum of OrigSeries, and point 1 is at X maximum.

To extend the TrendSeries, for example forward, change the point index 1:

procedure TForm1.Button1Click(Sender: TObject);

var 
  y, m, b: Double;

begin

  TF.CalculateTrend(m, b, OrigSeries, 0, OrigSeries.Count-1);
  TrendSeries.XValue[1]:=OrigSeries.Count+10;   // Extend last point by 10
  y:=m* (OrigSeries.Count+10) +b;
  TrendSeries.YValues[1]:=y;
end;