https://code.google.com/p/achartengine/ 


Code Test代码:
/workspace/AChartEngineTest   /workspace/appcompat_v7
/workspace/AChartEngineDemo

AChartEngine is a charting library for Android applications. It currently supports the following chart types:

  • line chart
  • area chart
  • scatter chart
  • time chart
  • bar chart
  • pie chart
  • bubble chart
  • doughnut chart
  • range (high-low) bar chart
  • dial chart / gauge
  • combined (any combination of line, cubic line, scatter, bar, range bar, bubble) chart
  • cubic line chart

All the above supported chart types can contain multiple series, can be displayed with the X axis horizontally (default) or vertically and support many other custom features. The charts can be built as a view that can be added to a view group or as an intent, such as it can be used to start an activity.

The model and the graphing code is well optimized such as it can handle and display huge number of values.

AChartEngine is currently at the 1.0.0 release. New chart types will be added in the following releases. Please keep sending your feedback such as we can continually improve this library.

Find us on Facebook, too: http://www.facebook.com/achartengine

Read a short introduction to AChartEngine here: http://www.javaadvent.com/2012/12/achartengine-charting-library-for.html

Another good tutorial can be read here: http://jaxenter.com/effort-free-graphs-on-android-with-achartengine-46199.html

1、导入jar包

2、直接列出实现的绘图以及代码

(1)

    1. package com.example.achartenginetest.charts;
    1. import java.text.DecimalFormat;
    1. import java.text.NumberFormat;
    1. import org.achartengine.ChartFactory;
    1. import org.achartengine.GraphicalView;
    1. import org.achartengine.model.CategorySeries;
    1. import org.achartengine.renderer.DefaultRenderer;
    1. import org.achartengine.renderer.SimpleSeriesRenderer;
    1. import android.content.Context;
    1. import android.graphics.Color;
    1. public class SimplePieChart extends AbstractChart{
    1. @Override
    1. public String getName() {
    1. return "本周血糖分析";
    1. }
    1. @Override
    1. public String getDesc() {
    1. // TODO Auto-generated method stub
    1. return "本周血糖分析";
    1. }
    1. @Override
    1. public GraphicalView execute(Context context) {
    1. double[] values = new double[] { 0.52, 0.2, 0.16, 0.12};
    1. int[] colors = new int[] { Color.BLUE, Color.GREEN, Color.YELLOW, Color.RED};
    1. DefaultRenderer renderer = buildCategoryRenderer(colors);
    1. renderer.setZoomButtonsVisible(false);
    1. renderer.setZoomEnabled(false);
    1. renderer.setChartTitleTextSize(30);
    1. renderer.setLabelsTextSize(25);
    1. renderer.setLabelsColor(Color.WHITE);
    1. renderer.setDisplayValues(true);
    1. renderer.setShowLabels(false);
    1. renderer.setPanEnabled(false);
    1. renderer.setZoomEnabled(false);
    1. SimpleSeriesRenderer mSimple = renderer.getSeriesRendererAt(0);
    1. NumberFormat nf = new DecimalFormat("正常00.#%");
    1. mSimple.setChartValuesFormat(nf);
    1. mSimple = renderer.getSeriesRendererAt(1);
    1. nf = new DecimalFormat("控制良好00.#%");
    1. mSimple.setChartValuesFormat(nf);
    1. mSimple = renderer.getSeriesRendererAt(2);
    1. nf = new DecimalFormat("控制一般00.#%");
    1. mSimple.setChartValuesFormat(nf);
    1. mSimple = renderer.getSeriesRendererAt(3);
    1. nf = new DecimalFormat("警告00.#%");
    1. mSimple.setChartValuesFormat(nf);
    1. GraphicalView view = ChartFactory.getPieChartView(context,
    1. buildCategoryDataset("血糖", values), renderer);
    1. return view;
    1. }
    1. @Override
    1. protected CategorySeries buildCategoryDataset(String title,double[]values){
    1. CategorySeries series = new CategorySeries(title);
    1. series.add("正常",values[0]);
    1. series.add("控制良好",values[1]);
    1. series.add("控制一般",values[2]);
    1. series.add("警告", values[3]);
    1. return series;
    1. }
    1. }
(2)

    1. package com.example.achartenginetest.charts;
    1. import java.text.DecimalFormat;
    1. import java.text.NumberFormat;
    1. import org.achartengine.ChartFactory;
    1. import org.achartengine.GraphicalView;
    1. import org.achartengine.model.CategorySeries;
    1. import org.achartengine.renderer.DefaultRenderer;
    1. import org.achartengine.renderer.SimpleSeriesRenderer;
    1. import android.content.Context;
    1. import android.graphics.Color;
    1. public class HighlightPieChart extends AbstractChart{
    1. @Override
    1. public String getName() {
    1. return "用药分析";
    1. }
    1. @Override
    1. public String getDesc() {
    1. return "用药分析";
    1. }
    1. @Override
    1. public GraphicalView execute(Context context) {
    1. double[] values = new double[] {0.86, 0.14};
    1. int[] colors = new int[] { Color.BLUE, Color.GREEN};
    1. DefaultRenderer renderer = buildCategoryRenderer(colors);
    1. renderer.setZoomButtonsVisible(false);
    1. renderer.setZoomEnabled(false);
    1. renderer.setChartTitleTextSize(30);
    1. renderer.setLabelsTextSize(25);
    1. renderer.setLabelsColor(Color.WHITE);
    1. renderer.setDisplayValues(true);
    1. renderer.setShowLabels(false);
    1. renderer.setPanEnabled(false);
    1. renderer.setZoomEnabled(false);
    1. SimpleSeriesRenderer mSimple = renderer.getSeriesRendererAt(0);
    1. NumberFormat nf = new DecimalFormat("正常用药00.#%");
    1. mSimple.setChartValuesFormat(nf);
    1. mSimple = renderer.getSeriesRendererAt(1);
    1. nf = new DecimalFormat("忘记用药00.#%");
    1. mSimple.setChartValuesFormat(nf);
    1. mSimple.setGradientEnabled(false);
    1. mSimple.setHighlighted(true);
    1. GraphicalView view = ChartFactory.getPieChartView(context,
    1. buildCategoryDataset("用药", values), renderer);
    1. return view;
    1. }
    1. @Override
    1. protected CategorySeries buildCategoryDataset(String title,double[]values){
    1. CategorySeries series = new CategorySeries(title);
    1. series.add("正常用药",values[0]);
    1. series.add("忘记用药",values[1]);
    1. return series;
    1. }
    1. }

(3)


    1. package com.example.achartenginetest.charts;
    1. import java.util.ArrayList;
    1. import java.util.List;
    1. import org.achartengine.ChartFactory;
    1. import org.achartengine.GraphicalView;
    1. import org.achartengine.chart.PointStyle;
    1. import org.achartengine.model.XYMultipleSeriesDataset;
    1. import org.achartengine.renderer.XYMultipleSeriesRenderer;
    1. import org.achartengine.renderer.XYSeriesRenderer;
    1. import android.content.Context;
    1. import android.graphics.Color;
    1. import android.graphics.Paint.Align;
    1. public class SimpleLineChart extends AbstractChart{
    1. @Override
    1. public String getName() {
    1. return "本周运动分析";
    1. }
    1. @Override
    1. public String getDesc() {
    1. return "本周运动分析,LineChart";
    1. }
    1. @Override
    1. public GraphicalView execute(Context context) {
    1. String[] titles = new String[] {"上周运动", "本周运动"};
    1. List<double[]> x = new ArrayList<double[]>();
    1. for (int i = 0; i < titles.length; i++) {
    1. x.add(new double[] { 1, 2, 3, 4, 5, 6, 7});
    1. }
    1. List<double[]> values = new ArrayList<double[]>();
    1. values.add(new double[] { 12.3, 12.5, 13.8, 16.8, 20.4, 24.4, 20.3});
    1. values.add(new double[] { 10, 10, 12, 15, 20, 24, 26});
    1. int[] colors = new int[] { Color.BLUE, Color.GREEN};
    1. PointStyle[] styles = new PointStyle[] { PointStyle.CIRCLE, PointStyle.DIAMOND};
    1. XYMultipleSeriesRenderer renderer = buildRenderer(colors, styles);
    1. int length = renderer.getSeriesRendererCount();
    1. for (int i = 0; i < length; i++) {
    1. ((XYSeriesRenderer) renderer.getSeriesRendererAt(i)).setFillPoints(true);
    1. }
    1. setChartSettings(renderer, "每周运动量", "时间", "运动时间(分钟)", 0.8, 7.2, 0, 30,
    1. Color.LTGRAY, Color.LTGRAY);
    1. // renderer.setXLabels(7);//设置X轴显示的刻度标签的个数
    1. renderer.setXLabels(0);//设置X轴显示的刻度采用自定义
    1. renderer.addXTextLabel(1, "周一");
    1. renderer.addXTextLabel(2, "周二");
    1. renderer.addXTextLabel(3, "周三");
    1. renderer.addXTextLabel(4, "周四");
    1. renderer.addXTextLabel(5, "周五");
    1. renderer.addXTextLabel(6, "周六");
    1. renderer.addXTextLabel(7, "周日");
    1. renderer.setYLabels(20);//设置Y轴显示的刻度标签的个数
    1. renderer.setShowGrid(true);
    1. renderer.setXLabelsAlign(Align.CENTER);
    1. renderer.setYLabelsAlign(Align.RIGHT);
    1. renderer.setZoomButtonsVisible(false);
    1. // renderer.setPanLimits(new double[] { 0.5, 7.5, 0, 30 }); /// /设置拖动时 X 轴 Y 轴允许的最大值最小值
    1. // renderer.setZoomLimits(new double[] { 0.5, 7.5, 0, 30 });
    1. renderer.setPanEnabled(false);
    1. renderer.setZoomEnabled(false);
    1. renderer.setAxisTitleTextSize(25);// 设置坐标轴标题文本大小
    1. renderer.setChartTitleTextSize(30); // 设置图表标题文本大小
    1. renderer.setLabelsTextSize(23); // 设置轴标签文本大小
    1. renderer.setXLabelsPadding(30);
    1. // renderer.setYLabelsPadding(50);
    1. renderer.setMargins(new int[]{0,80,0,0});
    1. renderer.setYLabelsVerticalPadding(50);
    1. XYMultipleSeriesDataset dataset = buildDataset(titles, x, values);
    1. // XYSeries series = dataset.getSeriesAt(0);
    1. // series.addAnnotation("Vacation", 6, 30);
    1. GraphicalView view = ChartFactory.getLineChartView(context, dataset, renderer);
    1. return view;
    1. }
    1. }

(4)


    1. package com.example.achartenginetest.charts;
    1. import java.util.ArrayList;
    1. import java.util.List;
    1. import java.util.Random;
    1. import org.achartengine.ChartFactory;
    1. import org.achartengine.GraphicalView;
    1. import org.achartengine.chart.CubicLineChart;
    1. import org.achartengine.chart.LineChart;
    1. import org.achartengine.chart.PointStyle;
    1. import org.achartengine.model.XYMultipleSeriesDataset;
    1. import org.achartengine.model.XYSeries;
    1. import org.achartengine.renderer.XYMultipleSeriesRenderer;
    1. import org.achartengine.renderer.XYSeriesRenderer;
    1. import org.achartengine.renderer.XYSeriesRenderer.FillOutsideLine;
    1. import android.content.Context;
    1. import android.graphics.Color;
    1. import android.graphics.Typeface;
    1. public class ComplexLineChart extends AbstractChart{
    1. private final static int NUM_X = 11;
    1. private final static int[] COLORS_DATA = new int[]{Color.RED, Color.YELLOW, Color.BLUE, Color.rgb(255, 124, 3),Color.GREEN,Color.rgb(85, 95, 10),Color.GRAY,Color.rgb(97,76,32)};
    1. private final static PointStyle[] STYLES_DATA = new PointStyle[]{PointStyle.CIRCLE,PointStyle.DIAMOND,PointStyle.SQUARE,PointStyle.TRIANGLE,PointStyle.POINT};
    1. private final static String[] TITLE_DAY = new String[]{"当天","昨天","前天"};
    1. private final static String[] TITLE_WEEK = new String[]{"本周","上一周","上两周","上三周"};
    1. private final static String[] TITLE_MONTH = new String[]{"本月","上一月","上两月","上三月"};
    1. private final static int DAY_DATA = 0;
    1. private final static int WEEK_DATA = 1;
    1. private final static int MONTH_DATA = 2;
    1. private XYMultipleSeriesRenderer mRenderer = null;
    1. private XYMultipleSeriesDataset mDataset = null;
    1. private int num_series = 0;
    1. private List<double[]> mDataList = null;
    1. private int mDataType = WEEK_DATA;
    1. private Random mRandom = null; //用于随机获取PointStyle;
    1. public ComplexLineChart(){
    1. initBackground();
    1. intParams();
    1. /**
    1. * 测试监测数据
    1. */
    1. mDataList = new ArrayList<double[]>();
    1. mDataList.add(new double[] {3.8, 7.8, 4.5, 3.9, 9.2, 4.0, 5.0, 8.2, 7.1, 5.0, 3.9});
    1. mDataList.add(new double[] {4.2, 8.8, 4.1, 3.7, 7.2, 4.1, 4.0, 8.7, 5.1, 5.0, 4.9});
    1. mDataList.add(new double[] {4.1, 9.0, 4.0, 3.1, 10.2, 5.1, 3.8, 8.5, 5.6, 4.0, 3.5});
    1. mDataList.add(new double[] {3.7, 6.1, 4.6, 4.1, 8.2, 4.1, 3.7, 9.5, 4.6, 2.0, 3.1});
    1. }
    1. public ComplexLineChart(List<double[]> data){
    1. initBackground();
    1. intParams();
    1. mDataList = data;
    1. }
    1. public ComplexLineChart(List<double[]> data, int datatype){
    1. initBackground();
    1. intParams();
    1. mDataList = data;
    1. mDataType = datatype;
    1. }
    1. private void intParams(){
    1. mRandom = new Random();
    1. }
    1. private void initBackground(){
    1. //*********************************************************************
    1. // 背景
    1. //*********************************************************************
    1. String[] titles = new String[] { "高血糖", "良好血糖","一般血糖","低血糖"};
    1. List<double[]> x = new ArrayList<double[]>();
    1. for (int i = 0; i < titles.length; i++) {
    1. x.add(new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11});
    1. }
    1. List<double[]> values = new ArrayList<double[]>();
    1. values.add(new double[] { 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12});
    1. values.add(new double[] { 6.1,10.0, 8.0, 6.1, 10.0, 8.0, 6.1, 10.0, 8.0, 6.1,6.1});
    1. values.add(new double[] { 5.1,8.5, 6.7, 5.1, 8.5, 6.7, 5.1, 8.5, 6.7, 5.1,5.1});
    1. values.add(new double[] { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4});
    1. int[] colors = new int[] { Color.argb(200, 255, 0, 0),
    1. Color.argb(200, 0, 0, 255),
    1. Color.argb(200, 0, 255, 0),
    1. Color.argb(200, 255, 0, 0)};
    1. PointStyle[] styles = new PointStyle[] { PointStyle.POINT, PointStyle.POINT, PointStyle.POINT, PointStyle.POINT};
    1. mRenderer = buildRenderer(colors, styles);
    1. setChartSettings(mRenderer, "", "时间", "血糖值", 0.8,11.2,0,12, Color.GRAY, Color.LTGRAY);
    1. mRenderer.setXLabels(0);//设置X轴显示的刻度采用自定义
    1. mRenderer.addXTextLabel(1, "早餐前");
    1. mRenderer.addXTextLabel(2, "早餐后1小时");
    1. mRenderer.addXTextLabel(3, "早餐后2小时");
    1. mRenderer.addXTextLabel(4, "午餐前");
    1. mRenderer.addXTextLabel(5, "午餐后1小时");
    1. mRenderer.addXTextLabel(6, "午餐后2小时");
    1. mRenderer.addXTextLabel(7, "晚餐前");
    1. mRenderer.addXTextLabel(8, "晚餐后1小时");
    1. mRenderer.addXTextLabel(9, "晚餐后2小时");
    1. mRenderer.addXTextLabel(10, "睡前");
    1. mRenderer.addXTextLabel(11, "凌晨2点");
    1. mRenderer.setYLabels(13);
    1. mRenderer.setChartTitleTextSize(30);
    1. mRenderer.setTextTypeface("sans_serif", Typeface.BOLD);
    1. mRenderer.setLabelsTextSize(20f);
    1. mRenderer.setAxisTitleTextSize(20);
    1. mRenderer.setLegendTextSize(20);
    1. // mRenderer.setShowLegend(true);
    1. mRenderer.setXLabelsAngle(-30);
    1. mRenderer.setZoomButtonsVisible(false);
    1. mRenderer.setPanEnabled(false);
    1. mRenderer.setZoomEnabled(false);
    1. int length = mRenderer.getSeriesRendererCount();
    1. for (int i = 0; i < length; i++) {
    1. XYSeriesRenderer seriesRenderer = (XYSeriesRenderer) mRenderer.getSeriesRendererAt(i);
    1. FillOutsideLine fill = new FillOutsideLine(FillOutsideLine.Type.BOUNDS_ALL);
    1. fill.setColor(colors[i]);
    1. seriesRenderer.addFillOutsideLine(fill);
    1. seriesRenderer.setLineWidth(2.5f);
    1. seriesRenderer.setDisplayChartValues(false);
    1. }
    1. mDataset = buildDataset(titles,x,values);
    1. num_series = titles.length;
    1. }
    1. @Override
    1. public String getName() {
    1. return "周血糖分析";
    1. }
    1. @Override
    1. public String getDesc() {
    1. return "周血糖分析,CubicLineChart & LineChart";
    1. }
    1. /**
    1. * 检查数据长度是否为11个取值点
    1. * @param data
    1. * @return 0:11个取值点,1:大于11个取值点,-1:小于11个取值点
    1. */
    1. private int checkData(double[] data){
    1. return data.length == NUM_X?0:(data.length<NUM_X?-1:1);
    1. }
    1. /**
    1. * 对数据进行修正,保证数据长度的正确性
    1. * @param data
    1. * @return
    1. */
    1. private double[] fixData(double[] data){
    1. int checkResult = checkData(data);
    1. if(checkResult == 0){
    1. return data;
    1. }else{
    1. double[] result = new double[NUM_X];
    1. if(checkResult == -1){
    1. for(int i =0; i<data.length;++i){
    1. result[i]=data[i];
    1. }
    1. for(int i = data.length; i<NUM_X; ++i){
    1. result[i] = 0;
    1. }
    1. }else{
    1. for(int i =0; i<NUM_X;++i){
    1. result[i]=data[i];
    1. }
    1. }
    1. return result;
    1. }
    1. }
    1. /**
    1. * 获取第indexData条数据线的点图
    1. * @return
    1. */
    1. private PointStyle getPointStyle(int indexData){
    1. if(null == mDataList || mDataList.size() == 0){
    1. return STYLES_DATA[0];
    1. }
    1. if(indexData<STYLES_DATA.length){
    1. return STYLES_DATA[indexData];
    1. }
    1. int index = mRandom.nextInt(STYLES_DATA.length);
    1. return STYLES_DATA[index];
    1. }
    1. /**
    1. * 获取第indexData条数据线的颜色
    1. * @param indexData
    1. * @return
    1. */
    1. private int getLineColor(int indexData){
    1. if(null == mDataList || mDataList.size() == 0){
    1. return COLORS_DATA[0];
    1. }
    1. if(indexData<COLORS_DATA.length){
    1. return COLORS_DATA[indexData];
    1. }
    1. int index = mRandom.nextInt(COLORS_DATA.length);
    1. return COLORS_DATA[index];
    1. }
    1. @Override
    1. public GraphicalView execute(Context context) {
    1. //*********************************************************************
    1. // 监测数值
    1. //*********************************************************************
    1. if(null != mDataList && mDataList.size() > 0){
    1. String[] titles;
    1. switch(mDataType){
    1. case DAY_DATA:
    1. titles = TITLE_DAY;
    1. break;
    1. case WEEK_DATA:
    1. titles = TITLE_WEEK;
    1. break;
    1. case MONTH_DATA:
    1. titles = TITLE_MONTH;
    1. break;
    1. default:
    1. titles = TITLE_WEEK;
    1. break;
    1. }
    1. int numLines = titles.length<=mDataList.size()?titles.length:mDataList.size();
    1. for(int j = 0; j< numLines; ++j){
    1. XYSeries week1Series = new XYSeries(titles[j]);
    1. double[] week1Data = fixData(mDataList.get(j));
    1. for(int i = 1; i<= week1Data.length; ++i){
    1. week1Series.add(i, week1Data[i-1]);
    1. }
    1. XYSeriesRenderer week1Renderer = new XYSeriesRenderer();
    1. week1Renderer.setColor(getLineColor(j));
    1. week1Renderer.setLineWidth(2.5f);
    1. week1Renderer.setPointStyle(getPointStyle(j));
    1. mDataset.addSeries(num_series, week1Series);
    1. mRenderer.addSeriesRenderer(num_series, week1Renderer);
    1. num_series++;
    1. }
    1. }
    1. //*********************************************************************
    1. // 将监测数值增加至图中
    1. //*********************************************************************
    1. String[] types_background = new String[] {CubicLineChart.TYPE,
    1. CubicLineChart.TYPE,
    1. CubicLineChart.TYPE,
    1. CubicLineChart.TYPE};
    1. String[] types = new String[num_series];
    1. for(int i = 0; i<types_background.length;++i){
    1. types[i] = types_background[i];
    1. }
    1. for(int i = types_background.length; i < num_series;++i){
    1. types[i] = LineChart.TYPE;
    1. }
    1. GraphicalView view = ChartFactory.getCombinedXYChartView(context, mDataset, mRenderer, types);
    1. return view;
    1. }
    1. }

(5)


    1. package com.example.achartenginetest.charts;
    1. import java.util.ArrayList;
    1. import java.util.List;
    1. import org.achartengine.ChartFactory;
    1. import org.achartengine.GraphicalView;
    1. import org.achartengine.chart.BarChart;
    1. import org.achartengine.chart.LineChart;
    1. import org.achartengine.chart.PointStyle;
    1. import org.achartengine.model.XYMultipleSeriesDataset;
    1. import org.achartengine.model.XYSeries;
    1. import org.achartengine.renderer.SimpleSeriesRenderer;
    1. import org.achartengine.renderer.XYMultipleSeriesRenderer;
    1. import org.achartengine.renderer.XYMultipleSeriesRenderer.Orientation;
    1. import org.achartengine.renderer.XYSeriesRenderer;
    1. import android.content.Context;
    1. import android.graphics.Color;
    1. import android.graphics.Paint.Align;
    1. public class HorizontalBarChart extends AbstractChart{
    1. private double[] mData = null;
    1. private double mAvg = 0;
    1. private double min_x = 0;
    1. private double max_x = 0;
    1. private double min_y = 0;
    1. private double max_y = 0;
    1. public HorizontalBarChart(){
    1. mData = new double[] {175,200,60,100,148};
    1. getAvg();
    1. initParas();
    1. }
    1. public HorizontalBarChart(double[] data){
    1. mData = data;
    1. getAvg();
    1. initParas();
    1. }
    1. private void initParas(){
    1. if(mData == null || mData.length==0){
    1. return;
    1. }
    1. max_x = mData.length+0.5;
    1. for(int i = 0; i<mData.length; ++i){
    1. max_y = max_y<mData[i]?mData[i]:max_y;
    1. }
    1. max_y += 50;
    1. }
    1. private void getAvg(){
    1. double sum = 0;
    1. for(int i = 0; i < mData.length; ++i){
    1. sum += mData[i];
    1. }
    1. mAvg= sum/mData.length;
    1. }
    1. @Override
    1. public String getName() {
    1. return "光荣榜";
    1. }
    1. @Override
    1. public String getDesc() {
    1. return "光荣榜,bar chart & line chart";
    1. }
    1. @Override
    1. public GraphicalView execute(Context context) {
    1. String[] titles = new String[] { "糖豆"};
    1. List<double[]> values = new ArrayList<double[]>();
    1. values.add(mData);
    1. int[] colors = new int[] {Color.BLUE};
    1. XYMultipleSeriesRenderer renderer = buildBarRenderer(colors);
    1. renderer.setOrientation(Orientation.VERTICAL);
    1. setChartSettings(renderer, "控糖光荣榜", "", "糖豆", min_x, max_x, min_y, max_y, Color.GRAY, Color.LTGRAY);
    1. renderer.setXLabels(0);
    1. renderer.addXTextLabel(1, "我");
    1. renderer.addXTextLabel(2, "老王");
    1. renderer.addXTextLabel(3, "张老太");
    1. renderer.addXTextLabel(4, "老李头");
    1. renderer.addXTextLabel(5, "小刘");
    1. renderer.setYLabels(6);
    1. renderer.setZoomEnabled(false);
    1. renderer.setPanEnabled(false);
    1. renderer.setZoomEnabled(false);
    1. renderer.setBarSpacing(0.5);
    1. renderer.setAxisTitleTextSize(25);// 设置坐标轴标题文本大小
    1. renderer.setChartTitleTextSize(30); // 设置图表标题文本大小
    1. renderer.setLabelsTextSize(23); // 设置轴标签文本大小
    1. renderer.setShowGrid(true);
    1. renderer.setXLabelsAlign(Align.CENTER);
    1. renderer.setYLabelsAlign(Align.RIGHT);
    1. renderer.setXLabelsPadding(30);
    1. renderer.setYLabelsPadding(30);
    1. renderer.setMargins(new int[]{0,30,80,30});
    1. renderer.setShowLegend(false);
    1. int length = renderer.getSeriesRendererCount();
    1. for (int i = 0; i < length; i++) {
    1. SimpleSeriesRenderer seriesRenderer = renderer.getSeriesRendererAt(i);
    1. seriesRenderer.setDisplayChartValues(false);
    1. }
    1. XYMultipleSeriesDataset mDataset = buildBarDataset(titles, values);
    1. /****************************************************************
    1. * 加入平均值
    1. ****************************************************************/
    1. XYSeries week1Series = new XYSeries("平均值");
    1. week1Series.add(min_x, mAvg);
    1. week1Series.add(max_x, mAvg);
    1. XYSeriesRenderer week1Renderer = new XYSeriesRenderer();
    1. week1Renderer.setColor(Color.BLUE );
    1. week1Renderer.setLineWidth(2.5f);
    1. week1Renderer.setPointStyle(PointStyle.POINT);
    1. mDataset.addSeries(1, week1Series);
    1. renderer.addSeriesRenderer(1, week1Renderer);
    1. String[] types = new String[]{BarChart.TYPE,LineChart.TYPE};
    1. GraphicalView view = ChartFactory.getCombinedXYChartView(context, mDataset, renderer, types);
    1. return view;
    1. }
    1. }

3、其他相关代码
MainActivity.java
    1. package com.example.achartenginetest;
    1. import java.util.ArrayList;
    1. import java.util.HashMap;
    1. import java.util.List;
    1. import java.util.Map;
    1. import android.app.ListActivity;
    1. import android.content.Intent;
    1. import android.os.Bundle;
    1. import android.view.View;
    1. import android.widget.ListView;
    1. import android.widget.SimpleAdapter;
    1. import com.example.achartenginetest.charts.ComplexLineChart;
    1. import com.example.achartenginetest.charts.HighlightPieChart;
    1. import com.example.achartenginetest.charts.HorizontalBarChart;
    1. import com.example.achartenginetest.charts.IChart;
    1. import com.example.achartenginetest.charts.SimpleLineChart;
    1. import com.example.achartenginetest.charts.SimplePieChart;
    1. import com.example.achartenginetest.charts.TableChart;
    1. public class MainActivity extends ListActivity {
    1. private final static String NAME = "name";
    1. private final static String DEC = "dec";
    1. private IChart[] mCharts = new IChart[] {new SimplePieChart(),new HighlightPieChart(),
    1. new SimpleLineChart(), new ComplexLineChart(),
    1. new HorizontalBarChart()};
    1. private String[] mItemText;
    1. private String[] mItemSummary;
    1. @Override
    1. protected void onCreate(Bundle savedInstanceState) {
    1. super.onCreate(savedInstanceState);
    1. initTextInList();
    1. setListAdapter(new SimpleAdapter(this, getListValues(), android.R.layout.simple_list_item_2,
    1. new String[] {NAME, DEC }, new int[] { android.R.id.text1,
    1. android.R.id.text2 }));
    1. }
    1. @Override
    1. protected void onListItemClick(ListView l, View v, int position, long id) {
    1. super.onListItemClick(l, v, position, id);
    1. Intent intent = null;
    1. Bundle bundle = new Bundle();
    1. bundle.putInt("position", position);
    1. if (position == mCharts.length) {
    1. intent = new Intent(this, TableChart.class);
    1. }else{
    1. intent = new Intent(this,ChartShowActivity.class);
    1. }
    1. intent.putExtras(bundle);
    1. startActivity(intent);
    1. }
    1. private void initTextInList(){
    1. int length = mCharts.length;
    1. mItemText = new String[length + 1];
    1. mItemSummary = new String[length + 1];
    1. for (int i = 0; i < length; i++) {
    1. mItemText[i] = mCharts[i].getName();
    1. mItemSummary[i] = mCharts[i].getDesc();
    1. }
    1. mItemText[length] = "血糖实际监测值";
    1. mItemSummary[length] = "Table";
    1. }
    1. private List<Map<String, String>> getListValues() {
    1. List<Map<String, String>> values = new ArrayList<Map<String, String>>();
    1. int length = mItemText.length;
    1. for (int i = 0; i < length; i++) {
    1. Map<String, String> v = new HashMap<String, String>();
    1. v.put(NAME, mItemText[i]);
    1. v.put(DEC, mItemSummary[i]);
    1. values.add(v);
    1. }
    1. return values;
    1. }
    1. }

ChartShowActivity.java
    1. package com.example.achartenginetest;
    1. import org.achartengine.GraphicalView;
    1. import android.app.Activity;
    1. import android.graphics.Color;
    1. import android.os.Bundle;
    1. import android.widget.FrameLayout;
    1. import android.widget.TextView;
    1. import com.example.achartenginetest.charts.ComplexLineChart;
    1. import com.example.achartenginetest.charts.HighlightPieChart;
    1. import com.example.achartenginetest.charts.HorizontalBarChart;
    1. import com.example.achartenginetest.charts.IChart;
    1. import com.example.achartenginetest.charts.SimpleLineChart;
    1. import com.example.achartenginetest.charts.SimplePieChart;
    1. public class ChartShowActivity extends Activity {
    1. private IChart[] mCharts = new IChart[] {new SimplePieChart(),new HighlightPieChart(),
    1. new SimpleLineChart(), new ComplexLineChart(),
    1. new HorizontalBarChart()};
    1. private int mIndex = 0;
    1. private TextView mText;
    1. private FrameLayout mLayout;
    1. @Override
    1. protected void onCreate(Bundle savedInstanceState) {
    1. // TODO Auto-generated method stub
    1. super.onCreate(savedInstanceState);
    1. this.setContentView(R.layout.activity_main);
    1. mLayout = (FrameLayout)this.findViewById(R.id.chart_layout);
    1. mText = (TextView)this.findViewById(R.id.text);
    1. mIndex = this.getIntent().getExtras().getInt("position");
    1. GraphicalView graphicalView = mCharts[mIndex].execute(this);
    1. if(null == graphicalView){
    1. return;
    1. }
    1. mLayout.removeAllViews();
    1. mLayout.setBackgroundColor(Color.BLACK);
    1. mLayout.addView(graphicalView, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,FrameLayout.LayoutParams.MATCH_PARENT));
    1. mText.setText(mCharts[mIndex].getName());
    1. }
    1. }

activity_main.xml
    1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    1. xmlns:tools="http://schemas.android.com/tools"
    1. android:layout_width="match_parent"
    1. android:layout_height="match_parent"
    1. tools:context="${relativePackage}.${activityClass}" >
    1. <TextView
    1. android:id="@+id/text"
    1. android:layout_width="match_parent"
    1. android:layout_height="wrap_content"
    1. android:layout_alignParentTop="true"
    1. android:text="@string/hello_world" />
    1. <FrameLayout
    1. android:id="@+id/chart_layout"
    1. android:layout_below="@+id/text"
    1. android:layout_width="match_parent"
    1. android:layout_height="wrap_content">
    1. </FrameLayout>
    1. </RelativeLayout>


附件列表

AchartEngine绘图引擎的更多相关文章

  1. Agg vs. Cairo 二维绘图引擎之比较和选择 .

    Agg vs. Cairo 二维绘图引擎之比较和选择 cheungmine 当今时代对于作为二维图形软件开发者, 是幸运的.因为除了Windows GDI/GDI+之外,我们还有很多其他的选择.而且这 ...

  2. 2D绘图引擎比较

    这个问题很普遍.最近在研究这个问题,在网上搜了一些资料,再结合自己的经验,谈谈自己的一些想法. 一.双缓存能提高绘图效率吗? 网上有篇文章:绘图效率完整解决方案——三种手段提高GDI/GDI+绘图效率 ...

  3. 关于XSuperMES项目使用的AChartEngine图表引擎

     非常多时候项目中我们须要对一些统计数据进行绘制表格,更多直观查看报表分析 结果. 基本有以下几种方法: 1:能够进行android  api进行draw这种话.效率比較低 2:使用开源绘表引擎, ...

  4. achartengine 绘图表神器

    http://code.google.com/p/achartengine/

  5. android AChartEngine图标引擎

    AChartEngine 1.在androi开发中的时候很多时候是要用图表将数据直观的显示出来的,这里就要用到AChartEngine. XMultipleSeriesRenderer 是经常要用到的 ...

  6. Android图表引擎AChartEngine之折线图使用

    最近在帮老师做一个课题,其中app端需要显示折线图以便直观地看数据波动,上网查了些资料后发现了这款图标引擎,另外感谢李坤老师的博客,帮助很大. 废话不多说,下面写代码. 一.AChartEngine是 ...

  7. iOS 2D绘图 (Quartz 2D) 概述

    本篇博客原文地址:http://blog.csdn.net/hello_hwc?viewmode=list 由于自己的项目需要,从网络上下载了许多关于绘制图形的demo,只是用在自己的项目中,很多地方 ...

  8. AChartEngine绘制图形

    AChartEngine是Android作图的方法之一,要使用AChartEngine,首先下载AChartEngine,按照以下方法将其jar包添加到工程中: 1.将achartengine-1.1 ...

  9. 25 个超棒的 HTML5 & JavaScript 游戏引擎开发库

    就像在汽车中,引擎完成主要的工作,使汽车看起来不可思议.游戏引擎同理,游戏开发者完成细节的工作,使游戏看起来真实.吸引人眼球.游戏引擎负责其余的事情.早期,游戏开发者通常从草图做起,花费高昂,且不容易 ...

随机推荐

  1. 数据库知识整理<一>

    关系型数据库知识整理: 一,关系型数据库管理系统简介: 1.1使用数据库的原因: 降低存储数据的冗余度 提高数据的一致性 可以建立数据库所遵循的标准 储存数据可以共享 便于维护数据的完整性 能够实现数 ...

  2. VIM编辑器的命令

    最近看书,说要熟悉一个文本编辑器的用法最好,在mac上找来找去,发现还是VIM最简单,是自带的,哈哈,决定先转下常用的命令,后续如果有时间,可以慢慢试用,慢慢分类,以下: VIM命令大全 保存文本和退 ...

  3. ajax异步请求Response.Redirect重定向

    一个ajax异步请求报错->捕获异常->重定向错误提示页面.  一个简单的流程 结果一直搞不定.重定向无效.各种百度之. 后来突然想起 ajax的请求是不能在后台重定向的. 如果硬要重定向 ...

  4. C语言 稀疏矩阵 压缩 实现

    稀疏矩阵压缩存储的C语言实现 (GCC编译). /** * @brief C语言 稀疏矩阵 压缩 实现 * @author wid * @date 2013-11-04 * * @note 若代码存在 ...

  5. 基于Criminisi算法的栅格影像数据敏感地物隐藏

    栅格影像数据敏感地物伪装是指通过计算机智能识别与计算,将影像数据中的敏感地物进行识别与提取,将敏感地物智能替换成公共地物,如草地.森林.湖泊.公园等.但目前该技术并不成熟,同时栅格影像数据敏感地物伪装 ...

  6. C#与数据库访问技术总结(十四)之DataAdapter对象

    DataAdapter对象 DataAdapter对象主要用来承接Connection和DataSet对象. DataSet对象只关心访问操作数据,而不关心自身包含的数据信息来自哪个Connectio ...

  7. javascript中重要概念-闭包-深入理解

    在上次的分享中javascript--函数参数与闭包--详解,对闭包的解释不够深入.本人经过一段时间的学习,对闭包的概念又有了新的理解.于是便把学习的过程整理成文章,一是为了加深自己闭包的理解,二是给 ...

  8. MySQL:InnoDB存储引擎的B+树索引算法

    很早之前,就从学校的图书馆借了MySQL技术内幕,InnoDB存储引擎这本书,但一直草草阅读,做的笔记也有些凌乱,趁着现在大四了,课程稍微少了一点,整理一下笔记,按照专题写一些,加深一下印象,不枉读了 ...

  9. duilib进阶教程 -- 设置资源路径 (15)

    在前面的教程里,虽然图片都放到了skin文件夹里,但是XML却都在外面,当XML比较多时,就不太好看啦,如下图: 所以需要整理一下,将XML也放入skin文件夹,这样exe的目录就简洁多了: 将XML ...

  10. JavaScript简介及基础知识(1)

    1.JavaScript是什么—它是个脚本语言,需要宿主文件,它的宿主文件是html文件. Javascript是一种脚本语言,比HTML要复杂.不过即便你先前不懂编程,也不用担心,因为Javascr ...