SciChart Android 2D Charts API > 2D Chart Types > The Stacked Column Series Type
The Stacked Column Series Type

Stacked Column series can be created by combining of StackedColumnRenderableSeries and VerticallyStackedColumnCollection/HorizontallyStackedColumnCollection classes. StackedColumnRenderableSeries shares many properties with the FastColumnRenderableSeries class, with the added feature that columns automatically stack by VerticallyStackedColumnCollection or HorizontallyStackedColumnCollection.

Examples for the Stacked Column Series can be found in the SciChart Android Examples Suite

Create a Stacked Column Series

To create a Stacked Column Series, use the following code:

// declare axes for chart
final IAxis xAxis = sciChartBuilder.newNumericAxis().build();
final IAxis yAxis = sciChartBuilder.newNumericAxis().build();

// declare arrays with data to append
final double[] porkData = new double[]{10, 13, 7, 16, 4, 6, 20, 14, 16, 10, 24, 11};
final double[] vealData = new double[]{12, 17, 21, 15, 19, 18, 13, 21, 22, 20, 5, 10};
final double[] tomatoesData = new double[]{7, 30, 27, 24, 21, 15, 17, 26, 22, 28, 21, 22};
final double[] cucumberData = new double[]{16, 10, 9, 8, 22, 14, 12, 27, 25, 23, 17, 17};
final double[] pepperData = new double[]{7, 24, 21, 11, 19, 17, 14, 27, 26, 22, 28, 16};

// declare and append data into data series
final IXyDataSeries<Double, Double> ds1 = sciChartBuilder.newXyDataSeries(Double.class, Double.class).withSeriesName("Pork Series").build();
final IXyDataSeries<Double, Double> ds2 = sciChartBuilder.newXyDataSeries(Double.class, Double.class).withSeriesName("Veal Series").build();
final IXyDataSeries<Double, Double> ds3 = sciChartBuilder.newXyDataSeries(Double.class, Double.class).withSeriesName("Tomato Series").build();
final IXyDataSeries<Double, Double> ds4 = sciChartBuilder.newXyDataSeries(Double.class, Double.class).withSeriesName("Cucumber Series").build();
final IXyDataSeries<Double, Double> ds5 = sciChartBuilder.newXyDataSeries(Double.class, Double.class).withSeriesName("Pepper Series").build();
final int data = 1992;
for (int i = 0; i < porkData.length; i++) {
     double xValue = data + i;
     ds1.append(xValue, porkData[i]);
     ds2.append(xValue, vealData[i]);
     ds3.append(xValue, tomatoesData[i]);
     ds4.append(xValue, cucumberData[i]);
     ds5.append(xValue, pepperData[i]);

// declare few StackedColumnRenderableSeries and assign data series to draw
final StackedColumnRenderableSeries porkSeries = sciChartBuilder.newStackedColumn().withDataSeries(ds1).withFillColor(0xff226fb7).withStrokeStyle(0xff22579D, 0f).build();
final StackedColumnRenderableSeries vealSeries = sciChartBuilder.newStackedColumn().withDataSeries(ds2).withFillColor(0xffff9a2e).withStrokeStyle(0xffBE642D, 0f).build();
final StackedColumnRenderableSeries tomatoSeries = sciChartBuilder.newStackedColumn().withDataSeries(ds3).withFillColor(0xffdc443f).withStrokeStyle(0xffA33631, 0f).build();
final StackedColumnRenderableSeries cucumberSeries = sciChartBuilder.newStackedColumn().withDataSeries(ds4).withFillColor(0xffaad34f).withStrokeStyle(0xff73953D, 0f).build();
final StackedColumnRenderableSeries pepperSeries = sciChartBuilder.newStackedColumn().withDataSeries(ds5).withFillColor(0xff8562b4).withStrokeStyle(0xff64458A, 0f).build();

// wrap porkSeries and vealSeries into VerticallyStackedColumnCollection to stack them vertically
final VerticallyStackedColumnsCollection verticalCollection1 = new VerticallyStackedColumnsCollection();

// wrap cucumberSeries, cucumberSeries and pepperSeriesinto VerticallyStackedColumnCollection to stack them vertically
final VerticallyStackedColumnsCollection verticalCollection2 = new VerticallyStackedColumnsCollection();

// wrap previously created VerticallyStackedColumnCollection into HorizontallyStackedColumnsCollection to stack resulting series horizontally
final HorizontallyStackedColumnsCollection columnsCollection = new HorizontallyStackedColumnsCollection();

// init chart
UpdateSuspender.using(surface, new Runnable() {
     public void run() {
         Collections.addAll(surface.getRenderableSeries(), columnsCollection);
         Collections.addAll(surface.getXAxes(), xAxis);
         Collections.addAll(surface.getYAxes(), yAxis);
         Collections.addAll(surface.getChartModifiers(), new RolloverModifier());
         Collections.addAll(surface.getChartModifiers(), new ZoomExtentsModifier());


VerticallyStackedColumnCollection is a special renderable series which allows to stack StackedColumnRenderableSeries vertically. Basically it's a collection and the order of items in this collection determines how series should be stacked and drawn ( the first item will be drawn as regular column series and the rest will be stacked on top of each other). You can create several instances of VerticallyStackedColumnCollection class and add them as renderable series into chart if you have several instances of StackedColumnRenderableSeries which should be stacked independently.



HorizontallyStackedColumnCollection is similar to VerticallyStackedColumnCollection and the only difference is that it stacks its items horizontally. By default it supports stacking of StackedColumnRenderableSeries or VerticallyStackedColumnCollection if you need to have both vertical and horizontal stacking in your application.