Search Results for

    Show / Hide Table of Contents

    The Stacked Mountain Series Type

    The Stacked Mountain series can be created by using StackedMountainRenderableSeries and VerticallyStackedSeriesCollection<T> classes. Stacked Mountain series shares most of its properties with the regular Mountain (Area) Series, with the added feature that mountains are automatically stacked (aggregate its Y-Values).

    Note

    In multi axis scenarios, a series has to be assigned to particular X and Y axes. This can be done by passing the axes IDs to the xAxisId, yAxisId properties.

    Stacked Mountain Series Type

    Note

    Examples of the Stacked Mountain Series can be found in the SciChart Android Examples Suite as well as on GitHub:

    • Native Example
    • Xamarin Example

    How the Stacking Works for Mountain Series

    Stacking Mountain series is handled by special renderableSeries - VerticallyStackedSeriesCollection<T>.

    Basically, it's a simple ObservableCollection<E> of Stacked Mountain Series, where the order of items in it 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.

    If you want to have several sets of Stacked Mountain Series which should be stacked independently, all you need to do - is to create corresponding amount of VerticallyStackedSeriesCollection<T> which will hold appropriate StackedMountainRenderableSeries.

    Create a Vertically Stacked Mountain Series

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

    • Java
    • Java with Builders API
    • Kotlin
    @Override
    protected void initExample(@NonNull SciChartSurface surface) {
        // 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 and append data into data series
        final IXyDataSeries<Double, Double> ds1 = new XyDataSeries<>(Double.class, Double.class);
        final IXyDataSeries<Double, Double> ds2 = new XyDataSeries<>(Double.class, Double.class);
    
        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 = createStackedMountain(ds1, 0xDDDBE0E1, 0x88B6C1C3);
        final StackedMountainRenderableSeries s2 = createStackedMountain(ds2, 0xDDACBCCA, 0x88439AAF);
    
        // wrap declared renderable series into VerticallyStackedMountainCollection to stack them vertically
        final VerticallyStackedMountainsCollection seriesCollection = new VerticallyStackedMountainsCollection();
        seriesCollection.add(s1);
        seriesCollection.add(s2);
    
        UpdateSuspender.using(surface, () -> {
            Collections.addAll(surface.getXAxes(), new NumericAxis(requireContext()));
            Collections.addAll(surface.getYAxes(), new NumericAxis(requireContext()));
    
            Collections.addAll(surface.getRenderableSeries(), seriesCollection);
        });
    }
    
    private StackedMountainRenderableSeries createStackedMountain(IXyDataSeries<Double, Double> dataSeries, int gradientStart, int gradientEnd) {
        final StackedMountainRenderableSeries stackedMountainSeries = new StackedMountainRenderableSeries();
    
        stackedMountainSeries.setDataSeries(dataSeries);
        stackedMountainSeries.setAreaStyle(new LinearGradientBrushStyle(0, 0, 0, 1, gradientStart, gradientEnd));
    
        return stackedMountainSeries;
    }
    
    @Override
    protected void initExample(@NonNull SciChartSurface surface) {
        // 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 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);
    
        UpdateSuspender.using(surface, () -> {
            Collections.addAll(surface.getXAxes(), sciChartBuilder.newNumericAxis().build());
            Collections.addAll(surface.getYAxes(), sciChartBuilder.newNumericAxis().build());
    
            Collections.addAll(surface.getRenderableSeries(), seriesCollection);
        });
    }
    
    override fun initExample(surface: SciChartSurface) {
        // declare arrays with data to append
        val yValues1 = doubleArrayOf(4.0, 7.0, 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)
        val yValues2 = doubleArrayOf(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 and append data into data series
        val ds1: IXyDataSeries<Double, Double> = XyDataSeries(
            Double::class.javaObjectType,
            Double::class.javaObjectType
        ).apply {
            yValues1.forEachIndexed { i, value ->
                append(i.toDouble(), value)
            }
        }
        val ds2: IXyDataSeries<Double, Double> = XyDataSeries(
            Double::class.javaObjectType,
            Double::class.javaObjectType
        ).apply {
            yValues2.forEachIndexed { i, value ->
                append(i.toDouble(), value)
            }
        }
    
        // wrap declared renderable series into VerticallyStackedMountainCollection to stack them vertically
        val seriesCollection = VerticallyStackedMountainsCollection().apply {
            add(createStackedMountain(ds1, -0x22241f1f, -0x77493e3d))
            add(createStackedMountain(ds2, -0x22534336, -0x77bc6551))
        }
    
        UpdateSuspender.using(surface) {
            Collections.addAll(surface.xAxes, NumericAxis(context))
            Collections.addAll(surface.yAxes, NumericAxis(context))
    
            Collections.addAll(surface.renderableSeries, seriesCollection)
        }
    }
    
    private fun createStackedMountain(
        ds: IXyDataSeries<Double, Double>,
        gradientStart: Int,
        gradientEnd: Int
    ): StackedMountainRenderableSeries? {
        return StackedMountainRenderableSeries().apply {
            dataSeries = ds
            areaStyle = LinearGradientBrushStyle(
                0f, 0f,
                0f, 1f,
                gradientStart, gradientEnd
            )
        }
    }
    

    100% Stacked Mountains

    Similarly to Stacked Column Series in SciChart it is possible to have Stacked Mountains, which fills all available vertical space. This mode is called 100% Stacked Mountains.

    To use it on your VerticallyStackedSeriesCollection<T>, just change the corresponding property of your collection:

    • isOneHundredPercent

    100% Stacked Mountain Series

    Back to top © 2011-2025 SciChart. All rights reserved. | sitemap.xml