tags:

views:

55

answers:

1

Hello!

I need to hide every second/third/forth item from the legend. IS there a way to achieve this in jFreeChart? thanks!

A: 

okay, just did it myself. This way I remove every second item from the legend. please leave comments!

LegendItemCollection legendItemsOld = plot.getLegendItems();
final LegendItemCollection legendItemsNew = new LegendItemCollection();

for(int i = 0; i< legendItemsOld.getItemCount(); i++){
  if(!(i%2 == 0)){
    legendItemsNew.add(legendItemsOld.get(i));
  }
}
LegendItemSource source = new LegendItemSource() {
LegendItemCollection lic = new LegendItemCollection();
{lic.addAll(legendItemsNew);}
public LegendItemCollection getLegendItems() {  
    return lic;
}
};
chart.addLegend(new LegendTitle(source));
tzippy