Page 1 of 1

Trend example

Posted: Thu Mar 06, 2014 7:55 pm
by 16468661
I just purchased Pro so I could use trends in my graph. I need to configure it in design mode-

Code: Select all

procedure TfrmPsrGraph.SetupGraph(const v1,v2,v3:shortstring);
var
  xBar3:TBarSeries;
  xTrend:TTrendFunction;
  m, b: Double;
begin
  xTrend:=TTrendFunction.Create(self);

  xBar3:=TBarSeries.Create(chtPSR);
  xBar3.ParentChart:=chtPSR;
  xBar3.SetFunction(xTrend);
  xBar3.DataSource:=fPSRTable;
  xBar3.CheckDataSource;
  xTrend.CalculateTrend(m,b,xBar3,0,xBar3.Count);

  xBar3.YValues.ValueSource:=v3;
  xBar3.XValues.ValueSource:='psrdate';
  xBar3.XValues.DateTime:=true;
  xBar3.ShowInLegend:=false;
  xBar3.Marks.Visible:=false;
  xBar3.color:=clBlue;
  xBar3.RefreshSeries;
  xBar3.Title:='s3';
  xBar3.ShowInLegend:=true;

  chtPSR.BottomAxis.ExactDateTime:=true;
  chtPSR.BottomAxis.DateTimeFormat:='m/d';
  chtPSR.BottomAxis.Increment:= DateTimeStep[dtOneDay];

end;
Obviously this doesnt draw a trend line. I see the bar graph but that's all. Any help will be appreciated.

Re: Trend example

Posted: Fri Mar 07, 2014 9:34 am
by yeray
Hello and welcome to the forums,

Note the functions need a series linked to them to be represented. In your case, a trend function is usually represented with a line series. Ie:

Code: Select all

uses Series, CurvFitt;

procedure TForm1.FormCreate(Sender: TObject);
var
  xBar:TBarSeries;
  xTrend:TTrendFunction;
  xLine: TLineSeries;
  m, b: Double;
begin
  xTrend:=TTrendFunction.Create(Self);

  xBar:=TBarSeries.Create(Self);
  xBar.ParentChart:=Chart1;
  //xBar.SetFunction(xTrend);
  xBar.FillSampleValues;
  //xBar.DataSource:=fPSRTable;
  //xBar.CheckDataSource;
  xTrend.CalculateTrend(m,b,xBar,0,xBar.Count);

  //xBar.YValues.ValueSource:=v3;
  //xBar.XValues.ValueSource:='psrdate';
  xBar.XValues.DateTime:=true;
  xBar.ShowInLegend:=false;
  xBar.Marks.Visible:=false;
  xBar.color:=clBlue;
  xBar.RefreshSeries;
  xBar.Title:='s3';
  xBar.ShowInLegend:=true;

  Chart1.BottomAxis.ExactDateTime:=true;
  Chart1.BottomAxis.DateTimeFormat:='m/d';
  Chart1.BottomAxis.Increment:= DateTimeStep[dtOneDay];

  xLine:=TLineSeries.Create(Self);
  xLine.ParentChart:=Chart1;
  xLine.SetFunction(xTrend);
  xLine.DataSource:=xBar;
  //xTrend.Period:=2;  //note you can change the period
end;
I'd suggest you to take a look at the tutorials and to the features demo, both shipped with the installation.
I've just replied a very similar question here

Re: Trend example

Posted: Fri Mar 07, 2014 2:23 pm
by 16468661
Thank you! Seeing the code makes it all look obvious now. btw, I couldn't find any examples of how to do this in design mode. Everything I saw was adjusting properties in the editor. I rarely use the editor in my projects.

Re: Trend example

Posted: Tue Mar 11, 2014 2:51 pm
by narcis
Hi Numinor,
Numinor wrote:I couldn't find any examples of how to do this in design mode.
You'll find some instructions in tutorial 7. Tutorials can be found at the program group created by binary package installers. If you still need some help don't hesitate to let us know.