sort by grouped month

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
jls
Newbie
Newbie
Posts: 27
Joined: Fri May 06, 2011 12:00 am

sort by grouped month

Post by jls » Tue Sep 20, 2011 8:21 am

I have a series grouped by month.
I want it to sorted correctly.

How?
Attachments
ChartSort.zip
(112.02 KiB) Downloaded 692 times

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: sort by grouped month

Post by Narcís » Tue Sep 20, 2011 9:14 am

Hi jls,

If you go to the Series -> General tab how are series sorted? You should try sorting them by text. If the problem persists could you please attach a simple example project we can run "as-is" to reproduce the problem here?

Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

jls
Newbie
Newbie
Posts: 27
Joined: Fri May 06, 2011 12:00 am

Re: sort by grouped month

Post by jls » Tue Sep 20, 2011 10:37 am

here is a sample
Attachments
Project2.zip
(102.45 KiB) Downloaded 690 times

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: sort by grouped month

Post by Narcís » Tue Sep 20, 2011 11:32 am

Hi jls,

To achieve what you request you can change your datasource to use a dataset like this:
jlsDataset.jpg
jlsDataset.jpg (60.22 KiB) Viewed 16685 times
Which produces this chart:
jlsResult.jpg
jlsResult.jpg (164.6 KiB) Viewed 16704 times
Is that what you were looking for?

Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

jls
Newbie
Newbie
Posts: 27
Joined: Fri May 06, 2011 12:00 am

Re: sort by grouped month

Post by jls » Tue Sep 20, 2011 11:43 am

No

It should be grouped my month and sorted by month (dec2010,jan2011,feb2011....)

It can be more than one row in each month


Jørgen

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: sort by grouped month

Post by Narcís » Wed Sep 21, 2011 2:42 pm

Hi Jørgen,

Ok, I see. We have done some modifications to DBChart.pas here that would let you achieve what you request. Since you are a source code customer you could try doing the modifications below to your code. If that's what you are looking for we will investigate further if those modifications can make into a production release.

Go to TCustomDBChart.RefreshDataSet method, at AddToSeries a nested method of another nested method(ProcessRecord), change this:

Code: Select all

          ASeries.Add(tmpMand,tmpXLabel,tmpColor);
for this:

Code: Select all

          if (GroupPrefix=dgNone) then
            ASeries.Add(tmpMand,tmpXLabel,tmpColor)
          else
            ASeries.AddXY(tmpNotMand,tmpMand,tmpXLabel,tmpColor);
Also, in the same nested method (ProcessRecord) in TCustomDBChart.RefreshDataSet method, change:

Code: Select all

        if Assigned(tmpData) then
           tmpNotMand:=TField(tmpData).AsFloat
//           ADataSet.GetFieldData(TField(tmpData), @tmpNotMand)  // v7 speed opt.
        else
           tmpNotMand:=0;
to this:

Code: Select all

        if Assigned(tmpData) then
           tmpNotMand:=TField(tmpData).AsFloat;
Please let us know if that's what you are looking for.

Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

jls
Newbie
Newbie
Posts: 27
Joined: Fri May 06, 2011 12:00 am

Re: sort by grouped month

Post by jls » Fri Sep 23, 2011 12:30 pm

Better, but the x location of the bars is not correct.

It should not care about the date, just the month.


Jørgen
Attachments
Untitled.png
Untitled.png (53.11 KiB) Viewed 16589 times

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: sort by grouped month

Post by Narcís » Fri Sep 23, 2011 3:13 pm

Hi Jørgen,

With the code as it stands the bars are set at the location of the date of the last value in that month. We assume that you would prefer the bars to centre on that month. Is that correct?

Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

jls
Newbie
Newbie
Posts: 27
Joined: Fri May 06, 2011 12:00 am

Re: sort by grouped month

Post by jls » Fri Sep 23, 2011 8:19 pm

Think it is tha same for me if it is first, midle or last day in the month, the problem is that it doesn't work like this for me. It uses the actual date. Take a look at the second image.


Jørgen

jls
Newbie
Newbie
Posts: 27
Joined: Fri May 06, 2011 12:00 am

Re: sort by grouped month

Post by jls » Wed Sep 28, 2011 11:54 am

Any solution?

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: sort by grouped month

Post by Narcís » Thu Sep 29, 2011 3:21 pm

Hi Jørgen,

Yes, we have a new solution proposal. Besides the changes I posted here last week you should also make a change at TCustomDBChart.RefreshDataSet in DBChart.pas at its nested CalcXPos function. You'll need to do the following:

1. Add a Word variable called WeekNum.
2. Replace this code:

Code: Select all

       dgWeek: result:=TeeStr(DateToWeek(tmpNotMand,Year))+'/'+TeeStr(Year);
    dgWeekDay: result:={$IFDEF D15}FormatSettings.{$ENDIF}ShortDayNames[DayOfWeek(tmpNotMand)];
      dgMonth: result:=FormatDateTime('MMM/yy',EncodeDate(Year,Month,1));
    dgQuarter: result:=TeeStr(1+((Month-1) div 3))+'/'+TeeStr(Year); // 5.02
       dgYear: result:=FormatDateTime('yyyy',EncodeDate(Year,1,1));
for this:

Code: Select all

       dgWeek: begin
                 WeekNum := DateToWeek(tmpNotMand,Year);
                 result:=TeeStr(WeekNum)+'/'+TeeStr(Year);
                 tmpNotMand := EncodeDateWeek(Year,WeekNum,4);
               end;
    dgWeekDay: begin
                 result:={$IFDEF D15}FormatSettings.{$ENDIF}ShortDayNames[DayOfWeek(tmpNotMand)];
                 DecodeDateWeek(tmpNotMand,Year,WeekNum,Day);
                 tmpNotMand := Day;
               end;
      dgMonth: begin
                  result:=FormatDateTime('MM/yy',EncodeDate(Year,Month,1));
                  tmpNotMand := EncodeDate(Year,Month,15);
               end;
    dgQuarter: begin
                  result:=TeeStr(1+((Month-1) div 3))+'/'+TeeStr(Year); //5.02
                  tmpNotMand := EncodeDate(Year,((1+((Month-1) div 3)-1)*3)+2,1);
               end;
       dgYear: begin
                  result:=FormatDateTime('yyyy',EncodeDate(Year,1,1));
                  tmpNotMand := EncodeDate(Year,6,30);
               end;
3. Finally add DateUtils at class' uses section.

Which produces this chart:
jlsProposal.jpg
jlsProposal.jpg (96.93 KiB) Viewed 16519 times
Is that what you expected? Notice there are some more DateTime grouping options now.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

jls
Newbie
Newbie
Posts: 27
Joined: Fri May 06, 2011 12:00 am

Re: sort by grouped month

Post by jls » Fri Sep 30, 2011 7:30 am

This is exactly what I want,
Thanks

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: sort by grouped month

Post by Narcís » Fri Sep 30, 2011 9:48 am

Hi Jørgen,

Thanks for your feedback. We will include this in the next maintenance release then.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply