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;
Have a line that is the average of the values of the points
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi McMClark,
You can use something like the code below as you can see at Tutorial 7 - Working with Functions.
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;
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |