- 浏览: 83233 次
- 性别:
- 来自: 广州
文章分类
最新评论
android图表工具achartengine之ChartFactory分析
要充分应用AChartEngine还需要查看源码,只有从本质上知道这些运作原理才能画出适合自己程序的图表
code:
package org.achartengine; import org.achartengine.chart.BarChart; import org.achartengine.chart.BubbleChart; import org.achartengine.chart.CombinedXYChart; import org.achartengine.chart.CubicLineChart; import org.achartengine.chart.DialChart; import org.achartengine.chart.DoughnutChart; import org.achartengine.chart.LineChart; import org.achartengine.chart.PieChart; import org.achartengine.chart.RangeBarChart; import org.achartengine.chart.ScatterChart; import org.achartengine.chart.TimeChart; import org.achartengine.chart.XYChart; import org.achartengine.model.CategorySeries; import org.achartengine.model.MultipleCategorySeries; import org.achartengine.model.XYMultipleSeriesDataset; import org.achartengine.renderer.DefaultRenderer; import org.achartengine.renderer.DialRenderer; import org.achartengine.renderer.XYMultipleSeriesRenderer; import android.content.Context; import android.content.Intent; public class ChartFactory//这个是AChartEngine的工厂类 { public static final String CHART = "chart"; public static final String TITLE = "title"; //---------------------以下这些是用GraphicalView显示的图表 需要寄托在一些Activity的布局上才能正常显示----------------------- public static final GraphicalView getLineChartView(Context context, XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer) {//LineChart可以画柱形图,折线图等 checkParameters(dataset, renderer); XYChart chart = new LineChart(dataset, renderer); return new GraphicalView(context, chart); } public static final GraphicalView getCubeLineChartView(Context context, XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer, float smoothness) {//这个是组合的线性图,可以自定义横轴,纵轴, checkParameters(dataset, renderer); XYChart chart = new CubicLineChart(dataset, renderer, smoothness); return new GraphicalView(context, chart); } public static final GraphicalView getScatterChartView(Context context, XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer) {//散点图 checkParameters(dataset, renderer); XYChart chart = new ScatterChart(dataset, renderer); return new GraphicalView(context, chart); } public static final GraphicalView getBubbleChartView(Context context, XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer) {//泡沫图 checkParameters(dataset, renderer); XYChart chart = new BubbleChart(dataset, renderer); return new GraphicalView(context, chart); } public static final GraphicalView getTimeChartView(Context context, XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer, String format) {//时间分布图 checkParameters(dataset, renderer); TimeChart chart = new TimeChart(dataset, renderer); chart.setDateFormat(format); return new GraphicalView(context, chart); } public static final GraphicalView getBarChartView(Context context, XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer, BarChart.Type type) {//柱状图 checkParameters(dataset, renderer); XYChart chart = new BarChart(dataset, renderer, type); return new GraphicalView(context, chart); } public static final GraphicalView getRangeBarChartView(Context context, XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer, BarChart.Type type) {//区域图 checkParameters(dataset, renderer); XYChart chart = new RangeBarChart(dataset, renderer, type); return new GraphicalView(context, chart); } public static final GraphicalView getCombinedXYChartView(Context context, XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer, String[] types) {//组合图,可以让柱状图+折线图+曲线+泡沫图融为一体 if ((dataset == null) || (renderer == null) || (types == null) || (dataset.getSeriesCount() != types.length)) { throw new IllegalArgumentException("Dataset, renderer and types should be not null and the datasets series count should be equal to the types length"); } checkParameters(dataset, renderer); CombinedXYChart chart = new CombinedXYChart(dataset, renderer, types); return new GraphicalView(context, chart); } public static final GraphicalView getPieChartView(Context context, CategorySeries dataset, DefaultRenderer renderer) {//饼图 checkParameters(dataset, renderer); PieChart chart = new PieChart(dataset, renderer); return new GraphicalView(context, chart); } public static final GraphicalView getDialChartView(Context context, CategorySeries dataset, DialRenderer renderer) {//刻表图 像汽车速度表那样的图 checkParameters(dataset, renderer); DialChart chart = new DialChart(dataset, renderer); return new GraphicalView(context, chart); } public static final GraphicalView getDoughnutChartView(Context context, MultipleCategorySeries dataset, DefaultRenderer renderer) {//圆圈图 checkParameters(dataset, renderer); DoughnutChart chart = new DoughnutChart(dataset, renderer); return new GraphicalView(context, chart); } //---------------------以下这些是用Intent(意图)显示的图表 可以不用寄托在Activity中也能正常显示----------------------- public static final Intent getLineChartIntent(Context context, XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer) { return getLineChartIntent(context, dataset, renderer, ""); } public static final Intent getCubicLineChartIntent(Context context, XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer, float smoothness) { return getCubicLineChartIntent(context, dataset, renderer, smoothness, ""); } public static final Intent getScatterChartIntent(Context context, XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer) { return getScatterChartIntent(context, dataset, renderer, ""); } public static final Intent getBubbleChartIntent(Context context, XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer) { return getBubbleChartIntent(context, dataset, renderer, ""); } public static final Intent getTimeChartIntent(Context context, XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer, String format) { return getTimeChartIntent(context, dataset, renderer, format, ""); } public static final Intent getBarChartIntent(Context context, XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer, BarChart.Type type) { return getBarChartIntent(context, dataset, renderer, type, ""); } public static final Intent getLineChartIntent(Context context, XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer, String activityTitle) { checkParameters(dataset, renderer); Intent intent = new Intent(context, GraphicalActivity.class); XYChart chart = new LineChart(dataset, renderer); intent.putExtra("chart", chart); intent.putExtra("title", activityTitle); return intent; } public static final Intent getCubicLineChartIntent(Context context, XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer, float smoothness, String activityTitle) { checkParameters(dataset, renderer); Intent intent = new Intent(context, GraphicalActivity.class); XYChart chart = new CubicLineChart(dataset, renderer, smoothness); intent.putExtra("chart", chart); intent.putExtra("title", activityTitle); return intent; } public static final Intent getScatterChartIntent(Context context, XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer, String activityTitle) { checkParameters(dataset, renderer); Intent intent = new Intent(context, GraphicalActivity.class); XYChart chart = new ScatterChart(dataset, renderer); intent.putExtra("chart", chart); intent.putExtra("title", activityTitle); return intent; } public static final Intent getBubbleChartIntent(Context context, XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer, String activityTitle) { checkParameters(dataset, renderer); Intent intent = new Intent(context, GraphicalActivity.class); XYChart chart = new BubbleChart(dataset, renderer); intent.putExtra("chart", chart); intent.putExtra("title", activityTitle); return intent; } public static final Intent getTimeChartIntent(Context context, XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer, String format, String activityTitle) { checkParameters(dataset, renderer); Intent intent = new Intent(context, GraphicalActivity.class); TimeChart chart = new TimeChart(dataset, renderer); chart.setDateFormat(format); intent.putExtra("chart", chart); intent.putExtra("title", activityTitle); return intent; } public static final Intent getBarChartIntent(Context context, XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer, BarChart.Type type, String activityTitle) { checkParameters(dataset, renderer); Intent intent = new Intent(context, GraphicalActivity.class); BarChart chart = new BarChart(dataset, renderer, type); intent.putExtra("chart", chart); intent.putExtra("title", activityTitle); return intent; } public static final Intent getRangeBarChartIntent(Context context, XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer, BarChart.Type type, String activityTitle) { checkParameters(dataset, renderer); Intent intent = new Intent(context, GraphicalActivity.class); RangeBarChart chart = new RangeBarChart(dataset, renderer, type); intent.putExtra("chart", chart); intent.putExtra("title", activityTitle); return intent; } public static final Intent getCombinedXYChartIntent(Context context, XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer, String[] types, String activityTitle) { if ((dataset == null) || (renderer == null) || (types == null) || (dataset.getSeriesCount() != types.length)) { throw new IllegalArgumentException("Datasets, renderers and types should be not null and the datasets series count should be equal to the types length"); } checkParameters(dataset, renderer); Intent intent = new Intent(context, GraphicalActivity.class); CombinedXYChart chart = new CombinedXYChart(dataset, renderer, types); intent.putExtra("chart", chart); intent.putExtra("title", activityTitle); return intent; } public static final Intent getPieChartIntent(Context context, CategorySeries dataset, DefaultRenderer renderer, String activityTitle) { checkParameters(dataset, renderer); Intent intent = new Intent(context, GraphicalActivity.class); PieChart chart = new PieChart(dataset, renderer); intent.putExtra("chart", chart); intent.putExtra("title", activityTitle); return intent; } public static final Intent getDoughnutChartIntent(Context context, MultipleCategorySeries dataset, DefaultRenderer renderer, String activityTitle) { checkParameters(dataset, renderer); Intent intent = new Intent(context, GraphicalActivity.class); DoughnutChart chart = new DoughnutChart(dataset, renderer); intent.putExtra("chart", chart); intent.putExtra("title", activityTitle); return intent; } public static final Intent getDialChartIntent(Context context, CategorySeries dataset, DialRenderer renderer, String activityTitle) { checkParameters(dataset, renderer); Intent intent = new Intent(context, GraphicalActivity.class); DialChart chart = new DialChart(dataset, renderer); intent.putExtra("chart", chart); intent.putExtra("title", activityTitle); return intent; } private static void checkParameters(XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer) { if ((dataset == null) || (renderer == null) || (dataset.getSeriesCount() != renderer.getSeriesRendererCount())) { throw new IllegalArgumentException("Dataset and renderer should be not null and should have the same number of series"); } } private static void checkParameters(CategorySeries dataset, DefaultRenderer renderer) { if ((dataset == null) || (renderer == null) || (dataset.getItemCount() != renderer.getSeriesRendererCount())) { throw new IllegalArgumentException("Dataset and renderer should be not null and the dataset number of items should be equal to the number of series renderers"); } } private static void checkParameters(MultipleCategorySeries dataset, DefaultRenderer renderer) { if ((dataset == null) || (renderer == null) || (!checkMultipleSeriesItems(dataset, renderer.getSeriesRendererCount()))) { throw new IllegalArgumentException("Titles and values should be not null and the dataset number of items should be equal to the number of series renderers"); } } private static boolean checkMultipleSeriesItems(MultipleCategorySeries dataset, int value) { int count = dataset.getCategoriesCount(); boolean equal = true; for (int k = 0; (k < count) && (equal); k++) { equal = dataset.getValues(k).length == dataset.getTitles(k).length; } return equal; } }
相关推荐
**Android图表引擎AChartEngine详解** AChartEngine是一款强大的开源库,专为Android平台设计,用于创建各种类型的图表,如柱状图、线形图、饼图等。它提供了丰富的功能,使得开发者能够轻松地在应用程序中集成图表...
**Android图表库AChartEngine详解** AChartEngine是一款在Android平台上用于创建各种图表的强大框架,其1.1.0版本提供了丰富的图表类型和高度自定义的功能。这个框架使得开发者能够轻松地在Android应用中集成数据...
Android图表引擎AChartEngine是一个强大的库,用于在Android应用程序中创建各种类型的图表,如线图、柱状图、饼图、散点图等。它提供了一个简单易用的API,使得开发者无需深入了解复杂的图形绘制机制就能实现丰富的...
**Android报表库aChartEngine详解:打造时间曲线图表** 在Android应用开发中,数据可视化是一项重要的功能,能够帮助用户直观地...无论是在数据分析、监控系统还是金融应用中,aChartEngine都是一个值得信赖的工具。
这篇博客“Android学习之AChartEngine折线图”将引导我们深入理解如何使用AChartEngine库来创建和定制折线图。 首先,我们需要了解AChartEngine的基本概念。AChartEngine是一个轻量级的库,它的主要功能是生成可...
AChartEngine 是一个安卓系统上制作图表的框架,使用简单,功能强大,目前它支持如下的图表类型:line chart (折线图),area chart (面积图;分区图,对比图),scatter chart ( 散点图),time chart (时间图;进度表),bar...
在Android应用开发中,视觉元素的使用对于数据的呈现至关重要,尤其当涉及到数据展示和分析时,折线图是一种常见的图表类型。`AChartEngine`是一个强大的库,它为Android开发者提供了一种简单的方式来创建各种类型的...
`ACHARTENGINE`是一个用Java编写的库,专为Android平台设计,支持多种类型的图表,包括折线图(LineChart)、饼图(PieChart)、柱状图(BarChart)、散点图(ScatterChart)以及更多其他图表类型。它简化了Android...
总之,AChartEngine 1.0.0是Android开发者的强大工具,它简化了报表的创建过程,提供了丰富的图表类型和自定义选项,帮助开发者快速构建具有专业可视化效果的应用程序。通过理解和掌握AChartEngine的使用,你可以...
总之,Achartengine是一个功能丰富的图表库,为Android开发者提供了方便的工具来展示数据。通过理解其基本结构,如`Dataset`、`Renderer`和`ChartView`,以及它们之间的关系,你可以有效地利用Achartengine创建美观...
AChartEngine是一个强大的开源库,专门用于在Android平台上创建各种类型的图表,如折线图、柱状图、饼图等。本文将深入探讨AChartEngine 1.0.0版本,分析其核心功能、使用方法以及相关示例,以帮助开发者更好地进行...
总之,AChartEngine作为Android原生的图表库,为开发者提供了便捷的图表创建工具,无论是简单还是复杂的图形需求,都能通过其强大的功能得到满足。通过学习和掌握AChartEngine的使用,可以提升Android应用的数据可视...
`achartengine`是一个开源的图表库,允许开发者轻松地为Android应用添加各种图表,如折线图、柱状图、饼图等。这个项目,"基于achartengine双Y轴动态图表Android源码",专门关注如何在同一个图表上使用两个不同的Y轴...
AChartEngine是一个开源的Android图表库,它提供了丰富的图表类型,包括折线图、柱状图、饼图等。使用AChartEngine,开发者可以轻松地为应用添加图表功能,无需深入了解图形渲染原理。以下是如何使用AChartEngine...
今天在做项目的时候用到了图表功能,记录下来 achartengine是google的一个开源项目,可以在https://code.google.com/p/achartengine/ 下载技术文档,jar包以及项目源代码 ...import org.achartengine.ChartFactory;
在Android应用开发中,报表...总之,`achartengine`是一个功能强大且易于使用的Android图表库,它简化了在移动应用中创建和展示图表的过程。结合API文档,开发者可以快速上手,为自己的应用增添生动的数据可视化元素。
在Android应用开发中,视觉元素的呈现...总之,AChartEngine是一个强大的工具,可以帮助Android开发者快速构建具有专业图表的应用。通过掌握其基本概念和使用方法,你可以为用户呈现美观且富有洞察力的数据可视化效果。
综上所述,AChartEngine为Android开发者提供了便利的图表开发工具,能够轻松地在应用中集成多种类型的图表,并通过自定义样式和交互功能,实现数据的直观展示。无论是初学者还是经验丰富的开发者,都能从中受益。