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)
Legend details to be re arranged
roshan012
Hi,
Request you suggest me below scenario.
Legend data is ascending order
CRITICAL
High
Low
Medium
I want to re arrange these data as
CRITICAL
HIGH
LOW
MEDIUM
HOW CAN GO WITH.
Find more posts tagged with
Comments
kclark
<a class='bbc_url' href='
http://www.birt-exchange.org/org/devshare/designing-birt-reports/1320-alter-pie-chart-legend-order-in-script/'>This
devshare</a> show's how to do it. By placing the code bellow in the onRender() of your pie chart.<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
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);
}
</pre>