Page 1 of 1

sort by grouped month

Posted: Tue Sep 20, 2011 8:21 am
by 16559245
I have a series grouped by month.
I want it to sorted correctly.

How?

Re: sort by grouped month

Posted: Tue Sep 20, 2011 9:14 am
by narcis
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.

Re: sort by grouped month

Posted: Tue Sep 20, 2011 10:37 am
by 16559245
here is a sample

Re: sort by grouped month

Posted: Tue Sep 20, 2011 11:32 am
by narcis
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 16415 times
Which produces this chart:
jlsResult.jpg
jlsResult.jpg (164.6 KiB) Viewed 16434 times
Is that what you were looking for?

Thanks in advance.

Re: sort by grouped month

Posted: Tue Sep 20, 2011 11:43 am
by 16559245
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

Re: sort by grouped month

Posted: Wed Sep 21, 2011 2:42 pm
by narcis
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.

Re: sort by grouped month

Posted: Fri Sep 23, 2011 12:30 pm
by 16559245
Better, but the x location of the bars is not correct.

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


Jørgen

Re: sort by grouped month

Posted: Fri Sep 23, 2011 3:13 pm
by narcis
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.

Re: sort by grouped month

Posted: Fri Sep 23, 2011 8:19 pm
by 16559245
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

Re: sort by grouped month

Posted: Wed Sep 28, 2011 11:54 am
by 16559245
Any solution?

Re: sort by grouped month

Posted: Thu Sep 29, 2011 3:21 pm
by narcis
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 16249 times
Is that what you expected? Notice there are some more DateTime grouping options now.

Re: sort by grouped month

Posted: Fri Sep 30, 2011 7:30 am
by 16559245
This is exactly what I want,
Thanks

Re: sort by grouped month

Posted: Fri Sep 30, 2011 9:48 am
by narcis
Hi Jørgen,

Thanks for your feedback. We will include this in the next maintenance release then.