MultiStacked Charts

Most charting tools allow you to stack bar and area charts in different modes. Most common are regular stack and 100% stack charts. Not only does Chart FX for Java allow you to stack charts using these common methods, but you can easily achieve MultiStacked charts where different series in the chart can be presented as different groups of stacked bar or area charts.

If you want to stack all series in the chart, you can use the Stacked property as follows:


// Regular stacked
chart1.setStacked(Stacked.NORMAL);
// or 100% stacked
chart1.setStacked(Stacked.STACKED_100);

The stacked property is also exposed by the Series object, with the difference that it will apply to a specific series in the chart. When you manipulate the Stacked property in the Series object you will instruct Chart FX to stack that series on top of the previous one, which must be of a stacked type (area or bar). For example, the following code creates a MultiStacked chart with a curve in front of the different stacked groups:


// Produce 2 bars and 1 curve
chart1.getSeries(0).setGallery(Gallery.BAR);
SeriesAttributes series2 = chart1.getSeries(1);
series2.setGallery(Gallery.BAR);
series2.setStacked(true);
// On top of 0
chart1.getSeries(2).setGallery(Gallery.BAR);
SeriesAttributes series4 = chart1.getSeries(3);
series4.setGallery(Gallery.BAR);
series4.setStacked(true);
// On top of 2
SeriesAttributes series5 = chart1.getSeries(4);
series5.setGallery(Gallery.BAR);
series5.setStacked(true);
//On top of 3
SeriesAttributes series6 = chart1.getSeries(5);
series6.setGallery(Gallery.CURVE);
series6.setColor(java.awt.Color.black);
// Adjust scale
chart1.recalcScale();

The previous code produces the following chart: