Compare Quarters of year in Summary

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
MaxDelphi
Newbie
Newbie
Posts: 1
Joined: Tue Aug 18, 2020 12:00 am

Compare Quarters of year in Summary

Post by MaxDelphi » Mon Aug 30, 2021 2:00 pm

I have multiple Memtables fetched from Database. Each of which contains records for one year.

I have added series to the DBChart with those memtables as Datasource (Summary grouped by Quarter).
Now i have the problem that the values for the different years are grouped by year. I would like to have for each quarter of all years next to each other. So that for example a comparison of Quarter 1 of 2020 and 2021 is possible. (Those to Quarters next to each other in a Bar Series)

Is there a way to do this?

Thanks in advance for the help
Max

Yeray
Site Admin
Site Admin
Posts: 9514
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Compare Quarters of year in Summary

Post by Yeray » Thu Sep 02, 2021 1:34 pm

Hello,

If I understand your situation, you probably have something like this:
Project1_2021-09-02_14-52-34.png
Project1_2021-09-02_14-52-34.png (17.21 KiB) Viewed 3595 times

Code: Select all

uses DBChart, Series, DateUtils;

var Chart1: TDBChart;
    memTables: array of TFDMemTable;

procedure TForm1.FormCreate(Sender: TObject);
var i, j: Integer;
    val: Integer;
    date: TDateTime;
begin
  Chart1:=TDBChart.Create(Self);
  Chart1.Parent:=Self;
  Chart1.Align:=alClient;

  Chart1.View3D:=False;
  Chart1.Gradient.Visible:=False;
  Chart1.Color:=clWhite;
  Chart1.Walls.Back.Gradient.Visible:=False;
  Chart1.Walls.Back.Color:=clWhite;

  SetLength(memTables, 2);
  for i:=0 to Length(memTables)-1 do
  begin
    memTables[i]:=TFDMemTable.Create(Self);
    memTables[i].FieldDefs.Add('Date', ftDateTime);
    memTables[i].FieldDefs.Add('Price', ftInteger);
    memTables[i].CreateDataSet;
    memTables[i].Open;

    val:=2000+Random(500);
    date:=StrToDateTime('01/01/2018');
    for j:=0 to (365*4)-1 do
    begin
      memTables[i].AppendRecord([date, val]);
      date:=IncDay(date);
      val:=val+Round(Random(10)-4.5);
    end;

    with Chart1.AddSeries(TBarSeries) do
    begin
      Marks.Hide;
      DataSource:=memTables[i];
      YValues.ValueSource:='#AVG#Price';
      XLabelsSource:='#QUARTER#Date';
    end;
  end;
end;
In that case, you should be able to create auxiliar memTables for each year and show them instead of the original tables.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply