whitespace COMPANY whitespace SERVICES whitespace PRODUCTS whitespace PURCHASE whitespace SUPPORT whitespace CONTACTS whitespace Home whitespace Contact Us whitespace Site Map whitespace
whitespace
WHY ARTFULBITS
whitespace
OUR APPROACH
whitespace
OUR TEAM
whitespace
FACT SHEET
whitespace
NEWS & EVENTS
whitespace
PRIVACY
whitespace
whitespace

StackedBar Chart Type

Overview

A stacked bar chart displays multiple series stacked on top of one another horizontally. Using a stacked bar chart is an effective way to present the absolute values of data points represented by the segments of each bar, as well as the total value represented by data points from each series stacked in a bar.

Creating the Stack Bar Chart

In order to create a stack column chart is needed to create two instances of chart series, set ChartType for those series as StackedBar and fill series with some data, like in the following sample:

zip archive Download sample

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
  <com.artfulbits.aiCharts.ChartView
    android:id="@+id/chartView"
    chart="@xml/chart"
    android:background="@android:drawable/alert_dark_frame" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"/>
</LinearLayout>
package com.artfulbits.aiCharts.stackedbarsample;

import com.artfulbits.aiCharts.ChartView;
import com.artfulbits.aiCharts.Base.*;
import com.artfulbits.aiCharts.Types.ChartTypes;

import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity
{
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		ChartView chartView = (ChartView) findViewById(R.id.chartView);
		
		ChartPalette palette = new ChartPalette(0xFFFFD700, 0xFFC0C0C0, 0xFFFF7F00);
		chartView.setPalette(palette);

		ChartSeries goldSeries = new ChartSeries("Gold", ChartTypes.StackedBar);
		ChartSeries silverSeries = new ChartSeries("Silver", ChartTypes.StackedBar);
		ChartSeries bronzeSeries = new ChartSeries("Bronze", ChartTypes.StackedBar);

		double[] gold = { 9, 10, 14, 9, 4, 3, 6, 5, 5, 2, 19 };
		double[] silver = { 15, 13, 7, 8, 6, 5, 6, 2, 2, 3, 20 };
		double[] bronze = { 13, 7, 5, 6, 6, 7, 2, 4, 4, 6, 25 };
		String[] labels = { "USA", "Germany", "Canada", "Norway", "Austria",
				"Russia Federation", "Korea", "China", "Sweden", "France", "Other" };

		for (int i = 0; i < labels.length; i++)
		{
			ChartPoint point = goldSeries.getPoints().addXY(i, gold[i]);

			silverSeries.getPoints().addXY(i, silver[i]);
			bronzeSeries.getPoints().addXY(i, bronze[i]);

			point.setAxisLabel(labels[i]);
		}

		chartView.getSeries().add(goldSeries);
		chartView.getSeries().add(silverSeries);
		chartView.getSeries().add(bronzeSeries);
		
		ChartArea area = chartView.getAreas().get(0);

		area.getDefaultYAxis().setLabelsMode(ChartAxis.LabelsMode.SeriesLabels);
	}
}
<?xml version="1.0" encoding="utf-8"?>
<ai:chart xmlns:ai="http://www.artfulbits.com/android/aiCharts">
	<ai:area/>
	<ai:legend/>
	<ai:title text="Winter Games: Medal Count" dock="Top" />
</ai:chart>
Company | Services | Practices | Technologies | Career | Contacts | Privacy
© 2005-2016 ArtfulBits. All rights reserved.