Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Sort X-axis when optionally grouped by Y-axis
faneprapad
I have a chart (Scatter Chart) that displays some error rates series with 4 columns: Error name(X-axis), and Error rate,in percentage values(Y-axis), Error interval and Sort order(sort order of the Error names).
I need to display these Error rates according to how they fit in the following intervals:
- <20% (colored in green)
- >=20% and <=50% (yellow)
- >50% (red)
I managed to display them in the chart(using scripting to color the markers) by "optionally grouping" them on a 3rd column, Error interval, that I have calculated within the same query on the database.
My problem is that when I "optionally group Y series" on the 3rd column, the Sorting on X-axis is not applied anymore on "sort order" column, but on Error name alphabetically. When I am using this grouping option on Y series, the sorting tab for X-axis values is disabled.
Is there any way of sorting the X-axis values using a different field - other than those used for X and Y-axis values - when the "optional Y series grouping" is used?
Find more posts tagged with
Comments
Migrateduser
I also have the same problem - with Month Names on the x-axis.
I can display Month Name and Sort on Month Number - which works fine.
But when I add an Optional Y Series Grouping (which I need as the Report is a stacked bar chart) the Sort on the x-axis is greyed out and the Month Name is defaulted in....
Migrateduser
I figured out how to display the month names in the correct order when you have an Optional Y Series Grouping, using Java Script...
1. Put the month number on the x-axis
2. Sort it in Ascending order
3. On the Layout tab highlight your chart and click the Script tab
4. Select the beforeDrawAxisLabel function
5. Paste in this function:
/**
* Called before rendering each label on a given Axis.
*
*
@param
axis
* Axis
*
@param
label
* Label
*
@param
icsc
* IChartScriptContext
*/
function beforeDrawAxisLabel( axis, label, icsc )
{
importPackage(Packages.org.eclipse.birt.chart.model.attribute);
if (axis.getOrientation() == Orientation.HORIZONTAL_LITERAL)
{
temp = label.getCaption().getValue();
if (temp == 1)
label.getCaption().setValue("Jan");
if (temp == 2)
label.getCaption().setValue("Feb");
if (temp == 3)
label.getCaption().setValue("Mar");
if (temp == 4)
label.getCaption().setValue("Apr");
if (temp == 5)
label.getCaption().setValue("May");
if (temp == 6)
label.getCaption().setValue("Jun");
if (temp == 7)
label.getCaption().setValue("Jul");
if (temp == 8)
label.getCaption().setValue("Aug");
if (temp == 9)
label.getCaption().setValue("Sep");
if (temp == 10)
label.getCaption().setValue("Oct");
if (temp == 11)
label.getCaption().setValue("Nov");
if (temp == 12)
label.getCaption().setValue("Dec");
axis.setLabel(label);
}
}
If anyone can find a better way then please let me know…
You should be able to follow this approach as well.
BIRT Excha
Hi BIRT-Dev,
I am using your solution to display month label for the chart.
However I need sort by Financial Month. So I create 2 addtional fields in the query FYEAR, and FMONTH (-5,-4, ....0,...6 for Jul, Aug ...Dec,..Jun).
Then I modified your code to:
......
if (temp == -5)
label.getCaption().setValue("Jul");
if (temp == -4)
label.getCaption().setValue("Aug");
if (temp == -3)
label.getCaption().setValue("Sep");
if (temp == -2)
label.getCaption().setValue("Oct");
if (temp == -1)
label.getCaption().setValue("Nov");
if (temp == 0)
label.getCaption().setValue("Dec");
......
The output match requirements.
Now I am thinking if can get Fmonth in the FX for Select Data like
if (data["month/fmonth"] >6)
{data["month/fmonth"]-12;}
else
{data["month/fmonth"];}
But the result is null.
Can you please advise? Thanks.