AChartEngine中大饼图

package com.sprd.chartexample;

import java.util.Random;

import org.achartengine.ChartFactory;
import org.achartengine.chart.BarChart.Type;
import org.achartengine.chart.PointStyle;
import org.achartengine.model.CategorySeries;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.model.XYSeries;
import org.achartengine.model.XYValueSeries;
import org.achartengine.renderer.DefaultRenderer;
import org.achartengine.renderer.SimpleSeriesRenderer;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYSeriesRenderer;

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

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

	private CategorySeries dataset = new CategorySeries("时间分布");

	private DefaultRenderer renderer = new DefaultRenderer();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// 设置背景为黑色
		renderer.setApplyBackgroundColor(true);
		renderer.setBackgroundColor(Color.BLACK);

		int[] colors = { Color.BLUE, Color.RED, Color.GREEN, Color.YELLOW,
				Color.LTGRAY };
		renderer.setLabelsTextSize(20);
		renderer.setChartTitle("pie chart");
		renderer.setChartTitleTextSize(30);
		renderer.setLegendTextSize(30);
		renderer.setLegendHeight(50);
		for (int i = 0; i < 5; i++) {
			dataset.add(i);
			SimpleSeriesRenderer r = new SimpleSeriesRenderer();
			r.setColor(colors[i]);
			renderer.addSeriesRenderer(r);
		}

		Intent intent = ChartFactory.getPieChartIntent(this, dataset, renderer,
				"统计");
		startActivity(intent);
	}
}


上面的代码不再使用XYMultipleSeriesDataset 数据集和XYMultipleSeriesRenderer传感器,因为不使用xy坐标轴,这是简单的一个图和一组数据,所以使用

private CategorySeries dataset = new CategorySeries("时间分布");

	private DefaultRenderer renderer = new DefaultRenderer();

 
  

就ok了。

图:

AChartEngine中大饼图_第1张图片

如果再加上以下代码:

if (i == 4) {
				//渐变
				r.setGradientEnabled(true);
				//渐变开始颜色
				r.setGradientStart(0, colors[i]);
				//渐变结束颜色
				r.setGradientStop(0, Color.GREEN);
				//楼梯效果
				r.setHighlighted(true);
			}

AChartEngine中大饼图_第2张图片

你可能感兴趣的:(语言学习[Android])