Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Sorting X-axis in a chart
sarika.np
In my application I need to create a chart based report whose X-axis will be quarters of year. <br />
For eg: Q1 2010, Q2 2010, Q3 2010, Q4 2010, Q1 2011 etc.<br />
<br />
But in the report generated, the X-axis values are not getting sorted. It is coming like <strong class='bbc'>Q1 2010, Q1 2011</strong>, Q2 2010, Q3 2010 etc. I have optional Y-axis grouping. <br />
<br />
So here, sorting should happen based on two things. <br />
<br />
1. Year<br />
2. Quater<br />
<br />
Please help me to resolve this issue.
Find more posts tagged with
Comments
averma
Hi sarika.np,
Right next to "Category (x) Series"(In Data Tab of chart wizard) there is "Edit grouping and sorting" button. If you select that you can specify "DateTime" as type and "Quarters" as unit. I was not able to run your design since I dont have the database setup but I am attaching a sample design that you can run in your environment.
Ashwini
sarika.np
Hi,
Thanks for the help. It works fine now.
I have another question. I am showing the X-axis based on the user input like Month, Quarter and Year using the following script. But when I am selecting month its format is coming like November 2010. Is it possible to format this like Nov-2010. I tried to set this by giving MMM-yyyy in Advanced section of X-axis format. But, then quarter and year is not coming. Please give me a solution for this.
importPackage( Packages. org.eclipse.birt.chart.model);
importPackage( Packages. org.eclipse.birt.chart.model.attribute);
rptDesignHandle = reportContext.getReportRunnable().designHandle.getDesignHandle();
chart = rptDesignHandle.findElement("NewChart");
item = chart.getReportItem();
cm = item.getProperty("chart.instance");
xAxis = cm.getAxes( ).get( 0 );
xSeriesDef = xAxis.getSeriesDefinitions( ).get( 0 );
xGrouping = xSeriesDef.getGrouping( );
if (params["rpPeriod"].equals("Q")) {
xGrouping.setGroupingUnit(GroupingUnitType.QUARTERS_LITERAL);
}else if(params["rpPeriod"].equals("M")) {
xGrouping.setGroupingUnit(GroupingUnitType.MONTHS_LITERAL);
xAxis.setFormatSpecifier(JavaDateFormatSpecifierImpl.create("MMM-yyyy"));
}else if (params["rpPeriod"].equals("Y")) {
xGrouping.setGroupingUnit(GroupingUnitType.YEARS_LITERAL);
}else{
xGrouping.setGroupingUnit(GroupingUnitType.MONTHS_LITERALL);
}
averma
The format string for quarter and year would be "qqq-yyyy" and "yyyy" respectively. Your javascript would have to dynamically change the format string based on the user selection.
Ashwini
sarika.np
Hi Ashwini,
Thanks for the reply. I got the desired output.