|
|
|
Re: How can you reorder the series of a line chart? [message #653725 is a reply to message #653714] |
Thu, 10 February 2011 15:24  |
Eclipse User |
|
|
|
Mike,
Here is one way to do it (using a beforeRendering script):
function beforeRendering( gcs, icsc )
{
//Script reverses chart legend order
importPackage(Packages.org.eclipse.birt.chart.computation);
importPackage(Packages.java.util);
importPackage(Packages.java.lang);
var llh = gcs.getRunTimeContext().getLegendLayoutHints();
//current legend
var liha = llh.getLegendItemHints( );
//new legend construct
var nliha = java.lang.reflect.Array.newInstance(LegendItemHints,
(liha.length));
if ( liha.length > 1 ){
for( idx=0; idx < liha.length; idx++ ){
var tli = liha[idx];
var oldpos = tli.getIndex();
var newpos = (liha.length-1)-idx;
var ntli = liha[newpos];
//valid legend entry
if( tli.getType() == LegendItemHints.Type.LG_ENTRY){
//create a new legend item using the the new items values
var lih = LegendItemHints.newEntry( ntli.getItemText(),
ntli.getValueText(), ntli.getSeriesDefinition(), ntli.getSeries(),
ntli.getIndex() );
lih.top(tli.getTop());
lih.left(tli.getLeft());
nliha[idx]=lih;
}else{
//separator
nliha[idx]=liha[idx];
}
}
}
//Create a new copy of the legend layout hints
var nllh = new LegendLayoutHints(
llh.getLegendSize(),llh.getTitleSize(),null,
llh.isMinSliceApplied(),llh.getMinSliceText(),
nliha );
//Update before rendering
gcs.getRunTimeContext().setLegendLayoutHints(nllh);
}
Jason
On 2/10/2011 2:31 PM, Mike Wulkan wrote:
> I tried that but it didn't work (at least not for me). It did show the
> legend changing in the preview, but not when I actually ran the report.
>
> I in the end I would like to directly control the order that the items
> appear. An example would be much appreciated.
|
|
|
Powered by
FUDForum. Page generated in 0.26633 seconds