Page 1 of 1

Sort order of bar graphs using DBCrossTabSource

Posted: Mon May 20, 2013 1:08 pm
by 8437895
I am trying to maintain some code that I inherited, so I do not entirely understand what I am reading. In addition, I have been unable to find any documentation about DBCrossTabSource either online or in the Help that came with the product. Perhaps someone can point me at the documentation.

When I use DBCrossTabSource, I see a number of bar graphs, each with a title/label. Unfortunately, if labels exist for "A", "B", and "C", they often appear as "B", "C", and then "A". That is, they are not correctly sorted.

Is there any way to have the graphs appear in alphabetical order, instead of randomly?

I am using 7.12 for Delphi 2007

Thanks!

Jon

Re: Sort order of bar graphs using DBCrossTabSource

Posted: Tue May 21, 2013 7:58 am
by yeray
Hi,

Try with SortByLabels function. Ie, for the first series in a chart:

Code: Select all

Chart1[0].SortByLabels(); 

Re: Sort order of bar graphs using DBCrossTabSource

Posted: Tue May 21, 2013 9:45 pm
by 8437895
Thanks for your help! I tried this, but I'm using a DBChart, and the code that you suggested does not compile. That is "DBChart1.SortByLabels" does not work.

Re: Sort order of bar graphs using DBCrossTabSource

Posted: Wed May 22, 2013 8:10 am
by yeray
Hi,

DBChart1.SortByLabels not! DBChart1[0].SortByLabels. DBChart1[0] is the first series in the DBChart1 chart.

Re: Sort order of bar graphs using DBCrossTabSource

Posted: Wed May 22, 2013 1:02 pm
by 8437895
Thank you, again! That does compile, but the charts still appear in an un-sorted order, as can be seen in the attached screen shot. I would like the Quarters to ascend uniformly

Re: Sort order of bar graphs using DBCrossTabSource

Posted: Thu May 23, 2013 9:02 am
by yeray
Hi,

I'm not sure if this is how you are creating your charts:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D:=false;
  Chart1.Legend.Visible:=false;

  with Chart1.AddSeries(THorizBarSeries) as THorizBarSeries do
  begin
    Marks.Visible:=false;

    Add(1, 'Post-analytic');
    Add(14, 'Analytic');
    Add(18, 'No error, or not yet classified');
    Add(207, 'Pre-analytic');

    //SortByLabels(loDescending);
  end;
end;
With the above, I get this:
unsorted.png
unsorted.png (6.58 KiB) Viewed 7370 times
Then, if I uncomment the SortByLabels(loDescending) line in the code above, this is what I get:
sorted.png
sorted.png (6.6 KiB) Viewed 7360 times
Isn't it how it behaves for you?
If you still find problems with it, please try to arrange a simple example project we can run as-is to reproduce the problem here.

Re: Sort order of bar graphs using DBCrossTabSource

Posted: Thu May 23, 2013 9:54 am
by 8437895
Thank you, again, for your help.

I am not trying to change the order of the bars within the charts. I am trying to change the order of the charts on the page.

The current order is

Quarter: 2005.1
Quarter: 2004.4
Quarter: 2003.1
Quarter: 2004.3

This order makes it difficult to find a particular chart, because the order appears to be random.

I imagine that the charts are in this order because they are sorted by Total Count, but I want the option of sorting them by their labels (Quarter: 2005.1)

Re: Sort order of bar graphs using DBCrossTabSource

Posted: Thu May 23, 2013 11:03 am
by yeray
Hi,

Please, try to arrange a simple example project we can run as-is to reproduce the problem here.

Re: Sort order of bar graphs using DBCrossTabSource

Posted: Thu May 23, 2013 6:02 pm
by 8437895
I did as you asked, and am now thinking that the problem is in some other code. Thank you for your time and help, but I doubt that the problem is in TeeChart.