Chart labels as computed percentages [message #1066415] |
Tue, 02 July 2013 10:38  |
Eclipse User |
|
|
|
Assume you have a chart displaying two years of data as bars for say 2012 and 2013.
How would you go about to display a percentage change on the bars of 2013 compared to the bars of 2012?
For example:
If January 2012 has 100 and January 2013 has 200, then on top of the January 2013 bar I would like to display 100%
I know I can change/format the labels in beforeDrawDataPointLabel( dph, label, icsc ),
but how and/or where do I go about computing the percentages?
can anyone point me to the "yellow birt road".....
thanks,
Harry
|
|
|
Re: Chart labels as computed percentages [message #1066577 is a reply to message #1066415] |
Wed, 03 July 2013 05:00  |
Eclipse User |
|
|
|
Never mind!
I figured it out by finding some other pieces of code. Here's how:
function beforeDrawDataPointLabel( dph, label, icsc )
{
currentPoint = dph.getOrthogonalValue();// or dph.getDisplayValue();
index = dph.getIndex();
// get previous point
seriesArray = icsc.getChartInstance().getAxes().get(0).getAssociatedAxes().get(0).getRuntimeSeries();
previousPoint = seriesArray[0].getDataSet().getValues()[index];
// compute %
changePercentage = ((currentPoint-previousPoint)/previousPoint)*100;
// display if change
if (changePercentage!=0)
{
label.getCaption().setValue(parseFloat(changePercentage).toFixed(2)+" %");
}
else
label.getCaption().setValue("");
}
The only hickup here is that if the two bars are equal (no change), then nothing, instead of 0 %, is displayed.
Oh well....
|
|
|
Powered by
FUDForum. Page generated in 0.02292 seconds