标签:
折线图:
- package org.achartengine.chartdemo.demo.chart;
-
- import java.util.ArrayList;
- import java.util.List;
-
- import org.achartengine.ChartFactory;
- import org.achartengine.chart.PointStyle;
- import org.achartengine.renderer.XYMultipleSeriesRenderer;
- import org.achartengine.renderer.XYSeriesRenderer;
-
- import android.content.Context;
- import android.content.Intent;
- import android.graphics.Color;
- import android.graphics.Paint.Align;
-
- public class AverageTemperatureChart extends AbstractDemoChart {
- public String getName() {
- return "Average temperature";
- }
-
- public String getDesc() {
- return "The average temperature in 4 Greek islands (line chart)";
- }
-
- public Intent execute(Context context) {
- String[] titles = new String[] { "Crete", "Corfu", "Thassos", "Skiathos" };
- List<double[]> x = new ArrayList<double[]>();
- for (int i = 0; i < titles.length; i++) {
- x.add(new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 });
- }
- List<double[]> values = new ArrayList<double[]>();
- values.add(new double[] { 12.3, 12.5, 13.8, 16.8, 20.4, 24.4, 26.4, 26.1, 23.6, 20.3, 17.2,
- 13.9 });
- values.add(new double[] { 10, 10, 12, 15, 20, 24, 26, 26, 23, 18, 14, 11 });
- values.add(new double[] { 5, 5.3, 8, 12, 17, 22, 24.2, 24, 19, 15, 9, 6 });
- values.add(new double[] { 9, 10, 11, 15, 19, 23, 26, 25, 22, 18, 13, 10 });
- int[] colors = new int[] { Color.BLUE, Color.GREEN, Color.CYAN, Color.YELLOW };
- PointStyle[] styles = new PointStyle[] { PointStyle.CIRCLE, PointStyle.DIAMOND,
- PointStyle.TRIANGLE, PointStyle.SQUARE };
- XYMultipleSeriesRenderer renderer = buildRenderer(colors, styles);
- int length = renderer.getSeriesRendererCount();
- for (int i = 0; i < length; i++) {
- ((XYSeriesRenderer) renderer.getSeriesRendererAt(i)).setFillPoints(true);
- }
- setChartSettings(renderer, "Average temperature", "Month", "Temperature", 0.5, 12.5, -10, 40,
- Color.LTGRAY, Color.LTGRAY);
- renderer.setXLabels(12);
- renderer.setYLabels(10);
- renderer.setShowGrid(true);
- renderer.setXLabelsAlign(Align.RIGHT);
- renderer.setYLabelsAlign(Align.CENTER);
- renderer.setZoomButtonsVisible(true);
-
- renderer.setPanLimits(new double[] { -10, 20, -10, 40 });
- renderer.setZoomLimits(new double[] { -10, 20, -10, 40 });
- Intent intent = ChartFactory.getLineChartIntent(context, buildDataset(titles, x, values),
- renderer, "Average temperature111");
- return intent;
- }
-
- }
饼图:
- package org.achartengine.chartdemo.demo.chart;
-
- import org.achartengine.ChartFactory;
- import org.achartengine.renderer.DefaultRenderer;
-
- import android.content.Context;
- import android.content.Intent;
- import android.graphics.Color;
-
- public class BudgetPieChart extends AbstractDemoChart {
- public String getName() {
- return "Budget chart";
- }
-
- public String getDesc() {
- return "The budget per project for this year (pie chart)";
- }
- public Intent execute(Context context) {
- double[] values = new double[] { 12, 14, 11, 10, 19 };
- int[] colors = new int[] { Color.BLUE, Color.GREEN, Color.MAGENTA, Color.YELLOW, Color.CYAN };
- DefaultRenderer renderer = buildCategoryRenderer(colors);
- renderer.setZoomButtonsVisible(true);
- renderer.setZoomEnabled(true);
- renderer.setChartTitleTextSize(20);
- return ChartFactory.getPieChartIntent(context, buildCategoryDataset("Project budget", values),
- renderer, "Budget");
- }
-
- }
柱状图:
- package org.achartengine.chartdemo.demo.chart;
-
- import java.util.ArrayList;
- import java.util.List;
-
- import org.achartengine.ChartFactory;
- import org.achartengine.chart.BarChart.Type;
- import org.achartengine.renderer.XYMultipleSeriesRenderer;
-
- import android.content.Context;
- import android.content.Intent;
- import android.graphics.Color;
- import android.graphics.Paint.Align;
-
- public class SalesStackedBarChart extends AbstractDemoChart {
- public String getName() {
- return "Sales stacked bar chart";
- }
-
- public String getDesc() {
- return "The monthly sales for the last 2 years (stacked bar chart)";
- }
-
- public Intent execute(Context context) {
- String[] titles = new String[] { "2008", "2007" };
- List<double[]> values = new ArrayList<double[]>();
- values.add(new double[] { 14230, 12300, 14240, 15244, 15900, 19200, 22030, 21200, 19500, 15500,
- 12600, 14000 });
- values.add(new double[] { 5230, 7300, 9240, 10540, 7900, 9200, 12030, 11200, 9500, 10500,
- 11600, 13500 });
- int[] colors = new int[] { Color.BLUE, Color.CYAN };
- XYMultipleSeriesRenderer renderer = buildBarRenderer(colors);
- setChartSettings(renderer, "Monthly sales in the last 2 years", "Month", "Units sold", 0.5,
- 12.5, 0, 24000, Color.GRAY, Color.LTGRAY);
- renderer.getSeriesRendererAt(0).setDisplayChartValues(true);
- renderer.getSeriesRendererAt(1).setDisplayChartValues(true);
- renderer.setXLabels(12);
- renderer.setYLabels(5);
- renderer.setXLabelsAlign(Align.LEFT);
- renderer.setYLabelsAlign(Align.LEFT);
- renderer.setPanEnabled(true, false);
-
- renderer.setZoomRate(1.1f);
- renderer.setBarSpacing(0.5f);
- return ChartFactory.getBarChartIntent(context, buildBarDataset(titles, values), renderer,
- Type.STACKED);
- }
- }
安卓图表引擎AChartEngine(一) - 简介
http://blog.csdn.net/lk_blog/article/details/7645509
安卓图表引擎AChartEngine(二) - 示例源码概述和分析
http://blog.csdn.net/lk_blog/article/details/7642751
安卓图表引擎AChartEngine(三) - 示例源码折线图、饼图和柱状图
http://blog.csdn.net/lk_blog/article/details/7645668
安卓图表引擎AChartEngine(四) - 源码示例嵌入Acitivity中的折线图
http://blog.csdn.net/lk_blog/article/details/7645665
安卓图表引擎AChartEngine(五) - Render和Dataset参数介绍
http://blog.csdn.net/lk_blog/article/details/7645661
安卓图表引擎AChartEngine(六) - 框架源码结构图
http://blog.csdn.net/lk_blog/article/details/7645671
安卓图表引擎AChartEngine(三) - 示例源码折线图、饼图和柱状图
标签:
原文地址:http://www.cnblogs.com/senior-engineer/p/4984552.html