Hi,
Let's say I have two monthly series for two years (2005-2006) and I want to do a month by month comparison so that I get 4 series each ranging from jan.-dec.
Is there a simple way to do this?
thanks,
nisbus
HOW TO: Compare multiple years?
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi nisbus,
You can achieve what you request doing something like this:
You can achieve what you request doing something like this:
Code: Select all
uses DateUtils;
procedure TForm1.FormCreate(Sender: TObject);
var i, j: Integer;
begin
Chart1.Axes.Bottom.DateTimeFormat:='MMM-yyyy';
Chart1.Axes.Bottom.Increment:=DateTimeStep[dtOneMonth];
//Chart1.Axes.Bottom.LabelsAngle:=90;
for i:=0 to Chart1.SeriesCount-1 do
begin
Chart1[i].XValues.DateTime:=true;
for j:=1 to 24 do
begin
if j<=12 then
Chart1[i].AddXY(EncodeDate(2005,j,1),random)
else
Chart1[i].AddXY(EncodeDate(2006,(j mod 13)+1,1),random);
end;
end;
end;
//Month to month comparision
procedure TForm1.Button1Click(Sender: TObject);
var i, j, tmpIndex: Integer;
tmpYear1, tmpYear2, tmpMonth: Word;
begin
Chart1.Axes.Bottom.DateTimeFormat:='MMMM';
for i:=0 to Chart1.SeriesCount-1 do
begin
tmpYear1:=YearOf(Chart1[i].XValues[0]);
tmpIndex:=-1;
for j:=0 to Chart1[i].Count-1 do
begin
tmpYear2:=YearOf(Chart1[i].XValues[j]);
if tmpYear1<>tmpYear2 then
begin
if tmpIndex=-1 then
begin
tmpIndex:=j;
Chart1.AddSeries(TLineSeries.Create(self));
Chart1[Chart1.SeriesCount-1].XValues.DateTime:=true;
end;
tmpMonth:=MonthOf(Chart1[i].XValue[j]);
Chart1[Chart1.SeriesCount-1].AddXY(EncodeDate(2005,tmpMonth,1),Chart1[i].YValue[j]);
end;
end;
Chart1[i].Delete(tmpIndex, Chart1[i].Count - tmpIndex);
end;
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 |
Hi, nisbus!
Generally speaking, for such task I could also use alternative horizontal axes: TopAxis if I needed to compare two years or additional custom axes if I needed to compare more
Generally speaking, for such task I could also use alternative horizontal axes: TopAxis if I needed to compare two years or additional custom axes if I needed to compare more
Regards, Alexander
=================
TeeChart Pro v8.05, Delphi 5 & Turbo Delphi Professional for Win32., Delphi & C++Builder 2009
=================
TeeChart Pro v8.05, Delphi 5 & Turbo Delphi Professional for Win32., Delphi & C++Builder 2009
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi nisbus,
You're very welcome! I'm glad to hear that helped.
You're very welcome! I'm glad to hear that helped.
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 |