Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » Custom sorting on a chart X axis
Custom sorting on a chart X axis [message #496294] Mon, 09 November 2009 15:55 Go to next message
Missing name Missing name is currently offline Missing name Missing name
Messages: 94
Registered: November 2009
Member
Hi,
I have created a chart with Strings as the X axis based on a column called Reporting_Period e.g.
row["Reporting_Period"]

These however are not sorted in the way i'd like due to the fact that alphabetical sorting is used.

There are 3 columns of the format
"W/E 15/11/2009" "W/E 08/11/2009" and "2 weeks old+ ".
The report can also be ran monthly in which case the W/E would be replaced with M/E.

When these are rendered I want them to be "date sorted" so this week/month should be the first column, then 1 week/month ago followed by 2 + weeks/months.
I have another column which is periods_old whose values correspond to the number of weeks/months old i.e. 0, 1 and 2 in the above example - is it possible to display the string value but sort on the integers? The "Sort on" field in the "Grouping and Sorting" menu is always disabled so I cant try to sort on the integer column. See attached screenshot for disabled section.

I can change the dataset to return just the date and use that but then I require some logic as follows, which im not sure where to put it (computed column editor doesnt seem to allow if/else syntax)

if(report_by_weeks) 
    Prepend W/E
else
    Prepend M/E


thanks for any ideas

[Updated on: Mon, 09 November 2009 15:59]

Report message to a moderator

Re: Custom sorting on a chart X axis [message #496472 is a reply to message #496294] Tue, 10 November 2009 09:04 Go to previous messageGo to next message
Missing name Missing name is currently offline Missing name Missing name
Messages: 94
Registered: November 2009
Member
I suppose to put it simply what i'm asking is it possible to have the X axis based on one column but sort the X axis values on another column?
Re: Custom sorting on a chart X axis [message #496553 is a reply to message #496294] Tue, 10 November 2009 14:17 Go to previous messageGo to next message
Missing name Missing name is currently offline Missing name Missing name
Messages: 94
Registered: November 2009
Member
In case anyone is wondering, I came up with the following solution.
Instead of returning the string "M/E 31/10/2009" and the number of months old in a separate column, I combined the two into a column of the form <periods_old>_<date_string> e.g.
"1_M/E 31/10/2009". This means that the ordering of the X axis values becomes trivial as they are just sorted based on the integer number at the start.
In order to remove the prefix for display purposes, I implemented the beforeDrawAxisLabel on the chart to substring the value about to be rendered. This removes the prefix but retains the original sorting of the values

/**
 * Called before rendering each label on a given Axis. This removes the 
 * prefix of the form "<periods_old>_" e.g. "0_" from the label. 
 * This prefix is used to make sorting simple as its based on integers
 * when this prefix is used
 * 
 * @param axis
 *            Axis
 * @param label
 *            Label
 * @param icsc
 *            IChartScriptContext
 */
function beforeDrawAxisLabel(axis, label, icsc) {
	if (axis.isCategoryAxis()) {	
		label.getCaption().setValue(label.getCaption().getValue().substring(2));
	}
}


Happy days!

[Updated on: Tue, 10 November 2009 14:18]

Report message to a moderator

Re: Custom sorting on a chart X axis [message #496605 is a reply to message #496553] Tue, 10 November 2009 16:21 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

Trevor,

Thanks for the update. Did you look at the sorting field in the chart
builder? You can sort on a different field than the one that is used
for the data. It is on the second tab of the chart wizard and it looks
like a down arrow.

Jason

TREVOR.HIGGINS@FINEOS.COM wrote:
> In case anyone is wnodering, I came up with the following solution.
> Instead of returning the string "M/E 31/10/2009" and the number of
> months old in a separate column, I combined the two into a column of the
> form "1_M/E 31/10/2009". This means that the ordering of the X axis
> values becomes trivial as they are just sorted based on the integer
> number at the start. In order to remove the prefix, I implemented the
> beforeDrawAxisLabel on the chart to substring the value about to be
> rendered. This removes the prefix but retains the original sorting of
> the values
>
>
> /**
> * Called before rendering each label on a given Axis. This removes the *
> prefix of the form "<periods_old>_" e.g. "0_" from the label. * This
> prefix is used to make sorting simple as its based on integers
> * when this prefix is used
> * * @param axis
> * Axis
> * @param label
> * Label
> * @param icsc
> * IChartScriptContext
> */
> function beforeDrawAxisLabel(axis, label, icsc) {
> if (axis.isCategoryAxis()) {
>
> label.getCaption().setValue(label.getCaption().getValue().su bstring(2));
> }
> }
>
>
> Happy days!
Re: Custom sorting on a chart X axis [message #557572 is a reply to message #496605] Wed, 08 September 2010 07:13 Go to previous messageGo to next message
can  is currently offline can
Messages: 2
Registered: September 2010
Junior Member
Hello,
I looked into the second tab of the chart builder, but I cannot see a way to choose a different column for the data to be sorted.

All I can see is this after pressing the down arrow:

Group and sorting
Data Sorting: Ascending/Descending or Unsorted
Grouping
Enabled Check-box
Type Unit
Interval
Aggregate Expression
Re: Custom sorting on a chart X axis [message #557729 is a reply to message #557572] Wed, 08 September 2010 15:40 Go to previous message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

What version of BIRT are you using? When you select ascending or
descending you should be able to choose a different sort column right
under it.

Jason

On 9/8/2010 3:13 AM, can wrote:
> Hello,
> I looked into the second tab of the chart builder, but I cannot see a
> way to choose a different column for the data to be sorted.
>
> All I can see is this after pressing the down arrow:
>
> Group and sorting
> Data Sorting: Ascending/Descending or Unsorted
> Grouping
> Enabled Check-box
> Type Unit Interval Aggregate Expression
>
Previous Topic:Table x-axis - Weekday Sorting
Next Topic:Formatting of table messed up when output spans multiple pages
Goto Forum:
  


Current Time: Thu Sep 18 21:52:28 GMT 2014

Powered by FUDForum. Page generated in 0.01678 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software