Order in the stacked bar chart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
chechaquo
Posts: 10
Joined: Tue Oct 28, 2008 12:42 pm

Order in the stacked bar chart

Post by chechaquo » Sun Oct 25, 2009 3:06 pm

Here is simple code which is rendering stacked bar chart

Code: Select all

public class ChartTest {
     public static void main(String[] args) {
        DefaultCategoryDataset ds = new DefaultCategoryDataset();
        ds.addValue(100, "A", "2001");
        ds.addValue(1000, "B", "2001");
        ds.addValue(600, "B", "2006");
        ds.addValue(5000, "A", "2006");
        JFreeChart stackedBar= ChartFactory.createStackedBarChart("My Chart", "AB", "Amounts",  ds, PlotOrientation.VERTICAL, true, true, false);
        ChartFrame cf = new ChartFrame("Test", stackedBar);
        cf.setSize(800, 600);
        cf.setVisible(true);
    }
}
Is it possible to render chart so for year 2001 it renders first A and then B and for 2006 first B and then A (i.e. small values first)? :roll:

Image

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: Order in the stacked bar chart

Post by paradoxoff » Sun Oct 25, 2009 11:20 pm

It should be possible by writing your own renderer. But I doubt that the effort (which I think will be considerable) is worth it.
It could be very confusing if the order of series changes from category to category. Hopefully, it is not a requirement by a customer! :wink:

Locked