| | | | Browse by category |
Question
How to have the data sets in the legend in the same order as in the Stacked chart area?
Answer
By default, the order of data sets used in the chart area is bottom-up, and in the legend area - if vertical - it is top-down.
If you are using a bar chart renderer in stacked mode, you will see by looking at the color used for each data set that the order in the legend and in the chart area is not the same.
To keep the same data set order in both components:
In JViews Charts 8.5 or higher: Use IlvLegend.setVerticalOrientation(SwingConstants.TOP)
.
In JViews Charts up to 8.1: You will need to override the IlvBarChartRenderer.createLegendItems()
method to reverse the order of legend items.
Here is an example of such a customization:
IlvBarChartRenderer disp = new
IlvBarChartRenderer(IlvBarChartRenderer.STACKED){
public IlvLegendItem[] createLegendItems() {
IlvLegendItem[] myItems =
super.createLegendItems();
IlvLegendItem[] modItems = new
IlvLegendItem[myItems.length];
for(int i=0;i<=myItems.length-1;i++){
modItems[i] =
myItems[(myItems.length-i)-1];
}
return modItems;
}
};