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.
Column Charts are very often used in Sales dashboards, as well as Fitness applications. This example will show how to generate a simple Column chart in code.
The FastColumnRenderableSeries 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 Column 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?
//******************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2017. All rights reserved.
//
// Web: http://www.scichart.com
// Support: support@scichart.com
// Sales: sales@scichart.com
//
// ColumnChartFragment.java is part of the SCICHART® Examples. Permission is hereby granted
// to modify, create derivative works, distribute and publish any part of this source
// code whether for commercial, private or personal use.
//
// The SCICHART® examples are distributed in the hope that they will be useful, but
// without any warranty. It is provided "AS IS" without warranty of any kind, either
// expressed or implied.
//******************************************************************************
package com.scichart.examples.fragments;
import android.view.animation.DecelerateInterpolator;
import com.scichart.charting.model.dataSeries.IXyDataSeries;
import com.scichart.charting.visuals.SciChartSurface;
import com.scichart.charting.visuals.axes.IAxis;
import com.scichart.charting.visuals.renderableSeries.FastColumnRenderableSeries;
import com.scichart.charting.visuals.renderableSeries.data.XSeriesRenderPassData;
import com.scichart.charting.visuals.renderableSeries.paletteProviders.IFillPaletteProvider;
import com.scichart.charting.visuals.renderableSeries.paletteProviders.PaletteProviderBase;
import com.scichart.core.framework.UpdateSuspender;
import com.scichart.core.model.IntegerValues;
import com.scichart.drawing.utility.ColorUtil;
import com.scichart.examples.R;
import com.scichart.examples.fragments.base.ExampleBaseFragment;
import java.util.Collections;
import butterknife.BindView;
public class ColumnChartFragment extends ExampleBaseFragment {
@BindView(R.id.chart)
SciChartSurface surface;
@Override
protected int getLayoutId() {
return R.layout.example_single_chart_fragment;
}
@Override
protected void initExample() {
final IAxis xAxis = sciChartBuilder.newNumericAxis().withGrowBy(0.1, 0.1).build();
final IAxis yAxis = sciChartBuilder.newNumericAxis().withGrowBy(0, 0.1).build();
IXyDataSeries<Integer, Integer> dataSeries = sciChartBuilder.newXyDataSeries(Integer.class, Integer.class).build();
final int[] yValues = {50, 35, 61, 58, 50, 50, 40, 53, 55, 23, 45, 12, 59, 60};
for (int i = 0; i < yValues.length; i++) {
dataSeries.append(i, yValues[i]);
}
final FastColumnRenderableSeries rSeries = sciChartBuilder.newColumnSeries()
.withStrokeStyle(0xFF232323, 0.4f)
.withDataPointWidth(0.7)
.withLinearGradientColors(ColorUtil.LightSteelBlue, ColorUtil.SteelBlue)
.withDataSeries(dataSeries)
.withPaletteProvider(new ColumnsPaletteProvider())
.build();
UpdateSuspender.using(surface, new Runnable() {
@Override
public void run() {
Collections.addAll(surface.getXAxes(), xAxis);
Collections.addAll(surface.getYAxes(), yAxis);
Collections.addAll(surface.getRenderableSeries(), rSeries);
Collections.addAll(surface.getChartModifiers(), sciChartBuilder.newModifierGroupWithDefaultModifiers().build());
sciChartBuilder.newAnimator(rSeries).withWaveTransformation().withInterpolator(new DecelerateInterpolator()).withDuration(3000).withStartDelay(350).start();
}
});
}
private class ColumnsPaletteProvider extends PaletteProviderBase<FastColumnRenderableSeries> implements IFillPaletteProvider {
/*
Gradients as in iOS, we don't support gradient palette provider yet
#1 start: 0xFFa9d34f; finish: 0xFF93b944; PEN 0xFF232323
#2 start: 0xFFfc9930; finish: 0xFFd17f28; PEN 0xFF232323
#3 start: 0xFFd63b3f; finish: 0xFFbc3337; PEN 0xFF232323
*/
private final IntegerValues colors = new IntegerValues();
private final int[] desiredColors = new int[]{0xFFa9d34f, 0xFFfc9930, 0xFFd63b3f};
protected ColumnsPaletteProvider() {
super(FastColumnRenderableSeries.class);
}
@Override
public void update() {
final XSeriesRenderPassData currentRenderPassData = (XSeriesRenderPassData) renderableSeries.getCurrentRenderPassData();
final int size = currentRenderPassData.pointsCount();
colors.setSize(size);
final int[] colorsArray = colors.getItemsArray();
final int[] indices = currentRenderPassData.indices.getItemsArray();
for (int i = 0; i < size; i++) {
final int index = indices[i];
colorsArray[i] = desiredColors[index % 3];
}
}
@Override
public IntegerValues getFillColors() {
return colors;
}
}
}