1,新建项目
2,添加libs文件夹,将achartengine-1.1.0.jar放置到libs下,
3,使用jar完成项目。
饼图使用为例:
-
package com.lwj.myachartenginertest;
-
-
import org.achartengine.ChartFactory;
-
import org.achartengine.model.CategorySeries;
-
import org.achartengine.renderer.DefaultRenderer;
-
import org.achartengine.renderer.SimpleSeriesRenderer;
-
-
import android.os.Bundle;
-
import android.app.Activity;
-
import android.graphics.Color;
-
import android.view.Menu;
-
import android.view.View;
-
-
public class MainActivity extends Activity {
-
@Override
-
public void onCreate(Bundle savedInstanceState) {
-
super.onCreate(savedInstanceState);
-
-
double[] values = new double[] { 12, 14, 11, 10, 19 };
-
int[] colors = new int[] { Color.BLUE, Color.GREEN, Color.MAGENTA, Color.WHITE, Color.CYAN };
-
DefaultRenderer renderer = buildCategoryRenderer(colors);//取得渲染器,并设置好颜色
-
renderer.setZoomButtonsVisible(true);//缩放控件
-
renderer.setZoomEnabled(true);//可缩放
-
renderer.setChartTitleTextSize(20);//
-
//生成饼图
-
View view = ChartFactory.getPieChartView(this, buildCategoryDataset("Project budget", values), renderer);
-
view.setBackgroundColor(Color.YELLOW);//背景颜色
-
setContentView(view);
-
}
-
-
protected DefaultRenderer buildCategoryRenderer(int[] colors) {
-
DefaultRenderer renderer = new DefaultRenderer();
-
renderer.setLabelsTextSize(15);
-
renderer.setLegendTextSize(15);
-
renderer.setMargins(new int[] { 20, 30, 15, 0 });
-
for (int color : colors) {
-
SimpleSeriesRenderer r = new SimpleSeriesRenderer();
-
r.setColor(color);
-
renderer.addSeriesRenderer(r);
-
}
-
return renderer;
-
}
-
-
protected CategorySeries buildCategoryDataset(String title, double[] values) {
-
CategorySeries series = new CategorySeries(title);
-
int k = 0;
-
for (double value : values) {
-
series.add("Project " + ++k + " (" + value + ")", value);
-
}
-
return series;
-
}
-
}
阅读(562) | 评论(0) | 转发(0) |