0

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.

Bob
  • 1
  • 1
  • Welcome to Stack Overflow. "I tried using" and "it gave an access violation" don't help a lot. Without code and the exact access violation information, it's hard to help you. "My car won't work when I try. What's wrong?" You need to provide actual information so we can try and help you find a solution. – Ken White Feb 26 '11 at 04:30
  • Also, need version of Delphi and of TeeChart (particularly the latter). – Argalatyr Mar 02 '11 at 12:34

2 Answers2

1

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;
Toby Fox
  • 105
  • 4
  • 11
David Berneda
  • 490
  • 5
  • 9
0

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.

Simon
  • 9,197
  • 13
  • 72
  • 115