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

Stacked Mountain series can be created by using StackedMountainRenderableSeries and VerticallyStackedMountainCollection classes. StackedMountainRenderableSeries shares many properties with the FastMountainRenderableSeries class, with the added feature that mountains automatically stack by VerticallyStackedMountainCollection.

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

Create a Vertically Stacked Mountain Series

To create a Vertically Stacked Mountain Series, use the following code:

// declare arrays with data to append
final double[] yValues1 = new double[] { 4.0,  7,    5.2,  9.4,  3.8,  5.1, 7.5,  12.4, 14.6, 8.1, 11.7, 14.4, 16.0, 3.7, 5.1, 6.4, 3.5, 2.5, 12.4, 16.4, 7.1, 8.0, 9.0 };
final double[] yValues2 = new double[] { 15.0, 10.1, 10.2, 10.4, 10.8, 1.1, 11.5, 3.4,  4.6,  0.1, 1.7, 14.4, 6.0, 13.7, 10.1, 8.4, 8.5, 12.5, 1.4, 0.4, 10.1, 5.0, 1.0 };        

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

// declare and append data into data series
final IXyDataSeries<Double, Double> ds1 = sciChartBuilder.newXyDataSeries(Double.class, Double.class).build();
final IXyDataSeries<Double, Double> ds2 = sciChartBuilder.newXyDataSeries(Double.class, Double.class).build();
for (int i = 0; i < yValues1.length; i++) ds1.append((double) i, yValues1[i]);
for (int i = 0; i < yValues2.length; i++) ds2.append((double) i, yValues2[i]);

// create few StackedMountainRenderable instances and assign data series to draw
final StackedMountainRenderableSeries s1 = sciChartBuilder.newStackedMountain().withDataSeries(ds1).withLinearGradientColors(0xDDDBE0E1, 0x88B6C1C3).build();
final StackedMountainRenderableSeries s2 = sciChartBuilder.newStackedMountain().withDataSeries(ds2).withLinearGradientColors(0xDDACBCCA, 0x88439AAF).build();

// wrap declared renderable series into VerticallyStackedMountainCollection to stack them vertically
final VerticallyStackedMountainsCollection seriesCollection = new VerticallyStackedMountainsCollection();
seriesCollection.add(s1);
seriesCollection.add(s2);

// init chart
UpdateSuspender.using(surface, new Runnable() {
     @Override
     public void run() {
         Collections.addAll(surface.getRenderableSeries(), seriesCollection);
         Collections.addAll(surface.getXAxes(), xAxis);
         Collections.addAll(surface.getYAxes(), yAxis);
     }
});

VerticallyStackedMountainsCollection

VerticallyStackedMountainCollection is a special renderable series which allows to stack  StackedMountainRenderableSeries 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 mountain series and the rest will be stacked on top of each other). You can create several instances of VerticallyStackedMountainCollection class and add them as renderable series into chart if you have several instances of StackedMountainRenderableSeries class which should be stacked independently.