Pre loader

Android Stacked Mountain Chart

Android Chart - Examples

SciChart Android ships with ~90 Android Chart Examples which you can browse, play with, view the source-code and even export each SciChart Android Chart Example to a stand-alone Android Studio project. All of this is possible with the new and improved SciChart Android Examples Suite, which ships as part of our Android Charts SDK.

Download Scichart Android

Demonstrates how to use Stacked Mountain API in SciChart Android. When you add multiple StackedMountainRenderableSeries into a VerticallyStackedMountainsCollection it allows to render mountain/areas stacked one above another. Data provided by its DataSeries can be used to render an XyDataSeries (which contains one X-point and one Y-point), XyyDataSeries (renders Y values), XyzDataSeries, HlDataSeries and OhlcDataSeries(renders Close values).

Tip!

To alter the line color, provide a pen by the setStrokeStyle() method. Calling the setAreaStyle() alters the fill. The setIsDigitalLine() method makes the series digital. The Mountain-Series supports semi-transparent and gradient fills and looks great!

The full source code for the Android Stacked Mountain Chart example is included below (Scroll down!).

Did you know you can also view the source code from one of the following sources as well?

  1. Clone the SciChart.Android.Examples from Github.
  2. Or, view source and export each example to an Android Studio project from the Java version of the SciChart Android Examples app.
  3. Also the SciChart Android Trial contains the full source for the examples (link below).

DOWNLOAD THE ANDROID CHART EXAMPLES

Kotlin: StackedMountainChartFragment.kt
View source code
//******************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2021. All rights reserved.
//
// Web: http://www.scichart.com
// Support: support@scichart.com
// Sales:   sales@scichart.com
//
// StackedMountainChartFragment.kt is part of SCICHART®, High Performance Scientific Charts
// For full terms and conditions of the license, see http://www.scichart.com/scichart-eula/
//
// This source code is protected by international copyright law. Unauthorized
// reproduction, reverse-engineering, or distribution of all or any portion of
// this source code is strictly prohibited.
//
// This source code contains confidential and proprietary trade secrets of
// SciChart Ltd., and should at no time be copied, transferred, sold,
// distributed or made available without express written permission.
//******************************************************************************

package com.scichart.examples.fragments.examples2d.multiChart.kt

import android.view.animation.DecelerateInterpolator
import com.scichart.charting.visuals.SciChartSurface
import com.scichart.examples.fragments.base.ExampleSingleChartBaseFragment
import com.scichart.examples.utils.Constant
import com.scichart.examples.utils.interpolator.DefaultInterpolator
import com.scichart.examples.utils.scichartExtensions.*

class StackedMountainChartFragment: ExampleSingleChartBaseFragment() {
    override fun initExample(surface: SciChartSurface) {
        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)

        surface.suspendUpdates {
            xAxes { numericAxis() }
            yAxes { numericAxis() }
            renderableSeries {
                verticallyStackedMountainsCollection {
                    stackedMountainRenderableSeries {
                        xyDataSeries<Double, Double> {
                            for (i in yValues1.indices) append(i.toDouble(), yValues1[i])
                        }
                        areaStyle = LinearGradientBrushStyle(0xDD47bde6, 0x88e2f4fd)

                        waveAnimation {
                            duration = Constant.ANIMATION_DURATION
                            startDelay = Constant.ANIMATION_START_DELAY
                            interpolator = DefaultInterpolator.getInterpolator()
                        }
                    }
                    stackedMountainRenderableSeries {
                        xyDataSeries<Double, Double> {
                            for (i in yValues2.indices) append(i.toDouble(), yValues1[i])
                        }
                        areaStyle = LinearGradientBrushStyle(0xDDae418d, 0x88efb4d3)

                        waveAnimation {
                            duration = Constant.ANIMATION_DURATION
                            startDelay = Constant.ANIMATION_START_DELAY
                            interpolator = DefaultInterpolator.getInterpolator()
                        }
                    }
                }
            }

            chartModifiers { tooltipModifier() }
        }
    }
}
Java: StackedMountainChartFragment.java
View source code
//******************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2021. All rights reserved.
//
// Web: http://www.scichart.com
// Support: support@scichart.com
// Sales:   sales@scichart.com
//
// StackedMountainChartFragment.java is part of SCICHART®, High Performance Scientific Charts
// For full terms and conditions of the license, see http://www.scichart.com/scichart-eula/
//
// This source code is protected by international copyright law. Unauthorized
// reproduction, reverse-engineering, or distribution of all or any portion of
// this source code is strictly prohibited.
//
// This source code contains confidential and proprietary trade secrets of
// SciChart Ltd., and should at no time be copied, transferred, sold,
// distributed or made available without express written permission.
//******************************************************************************

package com.scichart.examples.fragments.examples2d.multiChart;

import android.view.animation.DecelerateInterpolator;

import androidx.annotation.NonNull;

import com.scichart.charting.model.dataSeries.IXyDataSeries;
import com.scichart.charting.modifiers.TooltipModifier;
import com.scichart.charting.visuals.SciChartSurface;
import com.scichart.charting.visuals.renderableSeries.StackedMountainRenderableSeries;
import com.scichart.charting.visuals.renderableSeries.VerticallyStackedMountainsCollection;
import com.scichart.core.framework.UpdateSuspender;
import com.scichart.examples.fragments.base.ExampleSingleChartBaseFragment;
import com.scichart.examples.utils.Constant;
import com.scichart.examples.utils.interpolator.DefaultInterpolator;

import java.util.Collections;

public class StackedMountainChartFragment extends ExampleSingleChartBaseFragment {

    @Override
    protected void initExample(@NonNull SciChartSurface surface) {
        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 };
        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 };

        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]);

        final StackedMountainRenderableSeries s1 = sciChartBuilder.newStackedMountain().withDataSeries(ds1).withLinearGradientColors(0xDD47bde6, 0x88e2f4fd).build();
        final StackedMountainRenderableSeries s2 = sciChartBuilder.newStackedMountain().withDataSeries(ds2).withLinearGradientColors(0xDDae418d, 0x88efb4d3).build();

        final VerticallyStackedMountainsCollection seriesCollection = new VerticallyStackedMountainsCollection();
        seriesCollection.add(s1);
        seriesCollection.add(s2);

        UpdateSuspender.using(surface, () -> {
            Collections.addAll(surface.getRenderableSeries(), seriesCollection);
            Collections.addAll(surface.getXAxes(), sciChartBuilder.newNumericAxis().build());
            Collections.addAll(surface.getYAxes(), sciChartBuilder.newNumericAxis().build());
            Collections.addAll(surface.getChartModifiers(), new TooltipModifier());

            sciChartBuilder.newAnimator(s1).withWaveTransformation().withInterpolator(DefaultInterpolator.getInterpolator()).withDuration(Constant.ANIMATION_DURATION).withStartDelay(Constant.ANIMATION_START_DELAY).start();
            sciChartBuilder.newAnimator(s2).withWaveTransformation().withInterpolator(DefaultInterpolator.getInterpolator()).withDuration(Constant.ANIMATION_DURATION).withStartDelay(Constant.ANIMATION_START_DELAY).start();
        });
    }
}
Back to Android Chart Examples