SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, iOS Chart, Android Chart and JavaScript Chart Components
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.
Demonstrates how to use Stacked Column API to render columns grouped side by side. When you add multiple StackedColumnRenderableSeries into VerticallyStackedColumnsCollection for vertical grouping or into HorizontallyStackedColumnsCollection for horizontal grouping it allows to render them stacked one above another or side by side.
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).
Columns are drawn using the pens provided by the setStrokeStyle(PenStyle) (outline) and using the Brush provided by the setFillBrushStyle(BrushStyle) (fill).
Tip!
Do you need to change the width of a column? Try calling the setDataPointWidth() method passing in any number from 0.0 to 1.0. This alters how much space a column takes up.
The full source code for the Android Stacked Column Chart Grouped Side by Side example is included below (Scroll down!).
Did you know you can also view the source code from one of the following sources as well?
//******************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2021. All rights reserved.
//
// Web: http://www.scichart.com
// Support: support@scichart.com
// Sales: sales@scichart.com
//
// StackedColumnSideBySideFragment.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.Gravity.*
import android.view.animation.DecelerateInterpolator
import com.scichart.charting.numerics.labelProviders.FormatterLabelProviderBase
import com.scichart.charting.numerics.labelProviders.LabelFormatterBase
import com.scichart.charting.visuals.SciChartSurface
import com.scichart.charting.visuals.axes.AutoRange.Always
import com.scichart.charting.visuals.axes.NumericAxis
import com.scichart.data.model.DoubleRange
import com.scichart.examples.fragments.base.ExampleSingleChartBaseFragment
import com.scichart.examples.utils.scichartExtensions.*
class StackedColumnSideBySideFragment : ExampleSingleChartBaseFragment() {
override fun initExample(surface: SciChartSurface) {
val seriesData = mutableListOf(
doubleArrayOf(1.269, 1.330, 1.356, 1.304),
doubleArrayOf(1.004, 1.173, Double.NaN, 1.656),
doubleArrayOf(0.282, 0.310, Double.NaN, 0.439),
doubleArrayOf(0.214, 0.243, Double.NaN, 0.313),
doubleArrayOf(0.176, 0.201, Double.NaN, 0.261),
doubleArrayOf(0.146, 0.184, 0.196, 0.276),
doubleArrayOf(0.123, 0.152, 0.177, 0.264),
doubleArrayOf(0.130, 0.156, 0.166, 0.234),
doubleArrayOf(0.147, 0.139, 0.142, 0.109),
doubleArrayOf(0.126, 0.127, 0.127, 0.094),
doubleArrayOf(2.466, 2.829, 3.005, 4.306)
)
val countries = arrayOf("China", "India", "USA", "Indonesia", "Brazil", "Pakistan", "Nigeria", "Bangladesh", "Russia", "Japan", "Rest Of The World", "Total")
val fills = listOf(0xff3399ff, 0xff014358, 0xff1f8a71, 0xffbdd63b, 0xffffe00b, 0xfff27421, 0xffbb0000, 0xff550033, 0xff339933, 0xff00aba9, 0xff560068)
val strokes = listOf(0xff2D68BC, 0xff013547, 0xff1B5D46, 0xff7E952B, 0xffAA8F0B, 0xffA95419, 0xff840000, 0xff370018, 0xff2D732D, 0xff006C6A, 0xff3D0049)
surface.suspendUpdates {
xAxes {
numericAxis {
autoTicks = false
majorDelta = 1.0
minorDelta = 0.5
labelProvider = YearsLabelProvider()
}
}
yAxes {
numericAxis {
autoRange = Always
axisTitle = "billions of People"
growBy = DoubleRange(0.0, 0.1)
}
}
renderableSeries {
horizontallyStackedColumnsCollection {
for (i in 0 until seriesData.size) {
stackedColumnRenderableSeries {
xyDataSeries<Double, Double>(countries[i]) {
val points = seriesData[i]
for (j in points.indices) {
append(j.toDouble(), points[j])
}
}
fillBrushStyle = SolidBrushStyle(fills[i])
strokeStyle = SolidPenStyle(strokes[i], 0f)
waveAnimation { interpolator = DecelerateInterpolator() }
}
}
}
}
chartModifiers {
legendModifier { setLegendPosition(TOP or START, 10) }
tooltipModifier()
}
}
}
private class YearsLabelFormatter<T : NumericAxis> : LabelFormatterBase<T>() {
private val _xLabels = arrayOf("2000", "2010", "2014", "2050")
override fun update(axis: T) { }
override fun formatLabel(dataValue: Double): CharSequence {
val i = dataValue.toInt()
return if (i in 0 until 4) _xLabels[i] else ""
}
override fun formatCursorLabel(dataValue: Double): CharSequence {
val i = dataValue.toInt()
return when {
i in 0 until 4 -> { _xLabels[i] }
i < 0 -> { _xLabels[0] }
else -> { _xLabels[3] }
}
}
}
private class YearsLabelProvider : FormatterLabelProviderBase<NumericAxis>(NumericAxis::class.java, YearsLabelFormatter())
}
//******************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2021. All rights reserved.
//
// Web: http://www.scichart.com
// Support: support@scichart.com
// Sales: sales@scichart.com
//
// StackedColumnSideBySideFragment.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.Gravity;
import android.view.animation.DecelerateInterpolator;
import androidx.annotation.NonNull;
import com.scichart.charting.model.dataSeries.IXyDataSeries;
import com.scichart.charting.numerics.labelProviders.FormatterLabelProviderBase;
import com.scichart.charting.numerics.labelProviders.LabelFormatterBase;
import com.scichart.charting.visuals.SciChartSurface;
import com.scichart.charting.visuals.axes.AutoRange;
import com.scichart.charting.visuals.axes.IAxis;
import com.scichart.charting.visuals.axes.NumericAxis;
import com.scichart.charting.visuals.renderableSeries.HorizontallyStackedColumnsCollection;
import com.scichart.charting.visuals.renderableSeries.StackedColumnRenderableSeries;
import com.scichart.core.framework.UpdateSuspender;
import com.scichart.examples.fragments.base.ExampleSingleChartBaseFragment;
import java.util.ArrayList;
import java.util.Collections;
public class StackedColumnSideBySideFragment extends ExampleSingleChartBaseFragment {
@Override
protected void initExample(@NonNull SciChartSurface surface) {
final ArrayList<double[]> seriesData = new ArrayList<>();
seriesData.add(new double[]{1.269, 1.330, 1.356, 1.304});
seriesData.add(new double[]{1.004, 1.173, Double.NaN, 1.656});
seriesData.add(new double[]{0.282, 0.310, Double.NaN, 0.439});
seriesData.add(new double[]{0.214, 0.243, Double.NaN, 0.313});
seriesData.add(new double[]{0.176, 0.201, Double.NaN, 0.261});
seriesData.add(new double[]{0.146, 0.184, 0.196, 0.276});
seriesData.add(new double[]{0.123, 0.152, 0.177, 0.264});
seriesData.add(new double[]{0.130, 0.156, 0.166, 0.234});
seriesData.add(new double[]{0.147, 0.139, 0.142, 0.109});
seriesData.add(new double[]{0.126, 0.127, 0.127, 0.094});
seriesData.add(new double[]{2.466, 2.829, 3.005, 4.306});
final String[] countries = {"China", "India", "USA", "Indonesia", "Brazil", "Pakistan", "Nigeria", "Bangladesh", "Russia", "Japan", "Rest Of The World", "Total"};
final int[] fills = {0xff3399ff, 0xff014358, 0xff1f8a71, 0xffbdd63b, 0xffffe00b, 0xfff27421, 0xffbb0000, 0xff550033, 0xff339933, 0xff00aba9, 0xff560068};
final int[] strokes = {0xff2D68BC, 0xff013547, 0xff1B5D46, 0xff7E952B, 0xffAA8F0B, 0xffA95419, 0xff840000, 0xff370018, 0xff2D732D, 0xff006C6A, 0xff3D0049};
final IAxis xAxis = sciChartBuilder.newNumericAxis().withAutoTicks(false).withMajorDelta(1d).withMinorDelta(0.5).withLabelProvider(new YearsLabelProvider()).build();
final IAxis yAxis = sciChartBuilder.newNumericAxis().withAutoRangeMode(AutoRange.Always).withAxisTitle("billions of People").withGrowBy(0, 0.1).build();
UpdateSuspender.using(surface, () -> {
final HorizontallyStackedColumnsCollection columnsCollection = new HorizontallyStackedColumnsCollection();
for (int i = 0, size = seriesData.size(); i < size; i++) {
final double[] points = seriesData.get(i);
final IXyDataSeries<Double, Double> dataSeries = sciChartBuilder.newXyDataSeries(Double.class, Double.class).withSeriesName(countries[i]).build();
for (int j = 0; j < points.length; j++) {
dataSeries.append((double) j, points[j]);
}
final StackedColumnRenderableSeries rSeries = sciChartBuilder.newStackedColumn()
.withDataSeries(dataSeries)
.withFillColor(fills[i])
.withStrokeStyle(strokes[i], 0f)
.build();
sciChartBuilder.newAnimator(rSeries).withWaveTransformation().withInterpolator(new DecelerateInterpolator()).withDuration(3000).withStartDelay(350).start();
columnsCollection.add(rSeries);
}
Collections.addAll(surface.getXAxes(), xAxis);
Collections.addAll(surface.getYAxes(), yAxis);
Collections.addAll(surface.getRenderableSeries(), columnsCollection);
Collections.addAll(surface.getChartModifiers(), sciChartBuilder.newModifierGroup()
.withLegendModifier().withPosition(Gravity.TOP | Gravity.START, 10).build()
.withTooltipModifier().build()
.build());
});
}
private static class YearsLabelFormatter<T extends NumericAxis> extends LabelFormatterBase<T> {
private final String[] _xLabels = {"2000", "2010", "2014", "2050"};
@Override
public void update(NumericAxis axis) { }
@Override
public CharSequence formatLabel(double dataValue) {
int i = (int) dataValue;
String result = "";
if (i >= 0 && i < 4) {
result = _xLabels[i];
}
return result;
}
@Override
public CharSequence formatCursorLabel(double dataValue) {
int i = (int) dataValue;
String result;
if (i >= 0 && i < 4) {
result = _xLabels[i];
} else if (i < 0) {
result = _xLabels[0];
} else {
result = _xLabels[3];
}
return result;
}
}
private static class YearsLabelProvider extends FormatterLabelProviderBase<NumericAxis> {
public YearsLabelProvider() {
super(NumericAxis.class, new YearsLabelFormatter<>());
}
}
}