AChartEngine中轮胎图

package com.sprd.chartexample;

import org.achartengine.ChartFactory;
import org.achartengine.model.MultipleCategorySeries;
import org.achartengine.renderer.DefaultRenderer;
import org.achartengine.renderer.SimpleSeriesRenderer;
import org.achartengine.renderer.XYMultipleSeriesRenderer;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;

public class MainActivity extends Activity {
	public static final String TYPE = "type";

	private MultipleCategorySeries mDataset = new MultipleCategorySeries("轮胎图");

	private DefaultRenderer mRenderer = new DefaultRenderer();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mRenderer.setMargins(new int[] { 30, 30, 30, 30 });
		mRenderer.setApplyBackgroundColor(true);// 允许设置背景颜色
		mRenderer.setBackgroundColor(Color.BLACK);// 设置为黑色
		mRenderer.setChartTitle("Cpu Load");// 设置图表标题
		mRenderer.setChartTitleTextSize(30);// 设置图表标题文字的大小
		mRenderer.setLabelsTextSize(15);
		int[] colors = { Color.BLUE, Color.RED, Color.GREEN, Color.YELLOW,
				Color.LTGRAY };
		double[] load = { 10d, 10d, 10d, 10d, 10d };
		String[] titles = { "cpu0", "cpu1", "cpu2", "cpu3", "cpu4" };
		String[] cate = { "load", "fre","temp" };
		for (int i = 0; i < 3; i++) {
			mDataset.add(cate[i], titles, load);
			for (int k = 0; k < 5; k++) {
				SimpleSeriesRenderer r = new SimpleSeriesRenderer();
				r.setColor(colors[k]);
				mRenderer.addSeriesRenderer(r);
			}
		}

		Intent intent = ChartFactory.getDoughnutChartIntent(this, mDataset,
				mRenderer, "doughnut");
		startActivity(intent);
	}
}


数据集和渲染器换成了:


private MultipleCategorySeries mDataset = new MultipleCategorySeries("轮胎图");

	private DefaultRenderer mRenderer = new DefaultRenderer();

然后渲染的时候不是跟之前一样渲染每个子集,而是渲染每个子集中的每个元素。


图:


AChartEngine中轮胎图_第1张图片

你可能感兴趣的:(achartengine)