Page 1 of 1

Have a line that is the average of the values of the points

Posted: Wed Feb 08, 2006 6:43 pm
by 9337074
I am using Delphi 2005. I have a vcl application where I am building graphs at runtime based on queries. I want to have a line that is the average of the values from the query. What code should I add to the following to get that average line?

if TempResults_Query1.RecordCount = 1 then
begin
tmpBarSeries := TBarSeries.Create(Self);
DBChart1.AddSeries(tmpBarSeries);
With tmpBarSeries do
Begin
DataSource:= TempResults_Query1;
YValues.ValueSource := 'Score';
XLabelsSource := 'PublicationDate';
Title := strSubject
end;
end;

Posted: Thu Feb 09, 2006 8:08 am
by narcis
Hi McMClark,

You can use something like the code below as you can see at Tutorial 7 - Working with Functions.

Code: Select all

procedure TForm1.BitBtn5Click(Sender: TObject);
var tmpBarSeries1,tmpBarSeries2:TBarSeries;
tmpLineSeries:TLineSeries;
begin
With Chart1 do
begin
  //Add 2 data Series
  tmpBarSeries1:=TBarSeries.Create(self);
  tmpBarSeries2:=TBarSeries.Create(self);
  AddSeries(tmpBarSeries1);
  AddSeries(tmpBarSeries2);
  //Populate them with data (here random)
  tmpBarSeries1.FillSampleValues(10);
  tmpBarSeries2.FillSampleValues(10);
  //Add a series to be used for an Average Function
  tmpLineSeries:=TLineSeries.Create(self);
  AddSeries(tmpLineSeries);
  //Define the Function Type for the new Series
  tmpLineSeries.SetFunction(TAverageTeeFunction.Create(self));
  //Define the Datasource for the new Function Series
  //Datasource accepts the Series titles of the other 2 Series
  tmpLineSeries.DataSources.Clear;
  tmpLineSeries.DataSources.Add( tmpBarSeries1 );
  tmpLineSeries.DataSources.Add( tmpBarSeries2 );
  //    *Note - When populating your input Series manually you will need to
   //    use the Checkdatasource method
   //    - See the section entitled 'Defining a Datasource'
  //Change the Period of the Function so that it groups averages
  //every 2 Points
  tmpLineSeries.FunctionType.Period := 2;
End;