To fully apply AChartEngine, you also need to check the source code. Only by knowing the operating principles can you draw charts suitable for your program.
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. rangeBarCha Rt; 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. rende Rer. XYMultipleSeriesRenderer; import android. content. context; import android. content. intent; public class ChartFactory // This is the factory class of AChartEngine {public static final String CHART = "chart"; public static final String TITLE = "title "; // --------------------- The following charts displayed in GraphicalView must be placed on the layout of some activities before they can be normally displayed --------------------- public static final GraphicalView getLineChartView (Context context, XYMultipl ESeriesDataset dataset, XYMultipleSeriesRenderer renderer) {// LineChart can draw column charts, line charts and other checkParameters (dataset, renderer); XYChart chart = new LineChart (dataset, renderer); return new GraphicalView context, chart);} public static final GraphicalView getCubeLineChartView (Context context, XYMultipleSeriesDataset dataset, extends renderer, float smoothness) {// This is a combination of linear graphs. You can customize the horizontal, vertical, and chec KParameters (dataset, renderer); XYChart chart = new CubicLineChart (dataset, renderer, smoothness); return new GraphicalView (context, chart);} public static final GraphicalView getScatterChartView (Context context Context, XYMultipleSeriesDataset, XYMultipleSeriesRenderer renderer) {// scatter chart checkParameters (dataset, renderer); XYChart chart = new ScatterChart (dataset, renderer); return new GraphicalVi Ew (context, chart);} public static final GraphicalView getBubbleChartView (Context context, XYMultipleSeriesDataset, XYMultipleSeriesRenderer renderer) {// foam map 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) {// time distribution chart 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) {// bar chart checkParameters (da Taset, renderer); XYChart chart = new BarChart (dataset, renderer, type); return new GraphicalView (context, chart);} public static final GraphicalView getRangeBarChartView (Context context, XYMultipleSeriesDataset, XYMultipleSeriesRenderer renderer, BarChart. type type) {// region chart checkParameters (dataset, renderer); XYChart chart = new RangeBarChart (dataset, renderer, type); return new Graphical View (context, chart);} public static final GraphicalView getCombinedXYChartView (Context context, XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer, String [] types) {// composite diagram, if (dataset = null) | (renderer = null) | (types = null) | (dataset. getSeriesCount ()! = Types. length) {throw new IllegalArgumentException ("Dataset, renderer and types shocould be not null and the datasets series count shocould 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, CategorySe Ries dataset, DefaultRenderer renderer) {// pie chart 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) {// The checkParameters (dataset, renderer) of a table chart like a car speedometer ); dialChart chart = new DialChart (dataset, renderer); ret Urn new GraphicalView (context, chart);} public static final GraphicalView getDoughnutChartView (Context context, MultipleCategorySeries dataset, DefaultRenderer renderer) {// circle graph checkParameters (dataset, renderer ); doughnutChart chart = new DoughnutChart (dataset, renderer); return new GraphicalView (context, chart);} // ------------------- The following are Intent (Intent) the displayed chart can be normally displayed without being pinned in the Activity --------------- -------- Public static final Intent getLineChartIntent (Context context, XYMultipleSeriesDataset, XYMultipleSeriesRenderer renderer) {return getLineChartIntent (context, dataset, renderer, "");} public static final Intent publish (Context context Context, XYMultipleSeriesDataset, XYMultipleSeriesRenderer renderer, float smoothness) {return getCubicLineChartIntent (context, d Ataset, renderer, smoothness, "");} public static final Intent attributes (Context context, XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer) {return transform (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, extends 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", ch Art); intent. putExtra ("title", activityTitle); return intent;} public static final Intent values (Context context, XYMultipleSeriesDataset dataset, extends renderer, float smoothness, String activityTitle) {checkParameters (dataset, renderer); Intent intent = new Intent (context, GraphicalActivity. class); XYChart chart = new CubicLineChart (dataset, renderer, smooth Ness); intent. putExtra ("chart", chart); intent. putExtra ("title", activityTitle); return intent;} public static final Intent values (Context context, XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer, String activityTitle) {checkParameters (dataset, renderer ); intent intent = new Intent (context, GraphicalActivity. class); XYChart chart = new ScatterChart (dataset, rend Erer); intent. putExtra ("chart", chart); intent. putExtra ("title", activityTitle); return intent;} public static final Intent values (Context context, XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer, String activityTitle) {checkParameters (dataset, renderer ); intent intent = new Intent (context, GraphicalActivity. class); XYChart chart = new BubbleChart (dataset, render Er); intent. putExtra ("chart", chart); intent. putExtra ("title", activityTitle); return intent;} public static final Intent getTimeChartIntent (Context context, XYMultipleSeriesDataset dataset, extends renderer, String format, String activityTitle) {checkParameters (dataset, renderer); Intent intent = new Intent (context, GraphicalActivity. class); TimeChart chart = new TimeChart (data Set, 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 (con Text, 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, XYMultipleSeriesRenderer renderer, String [] types, String activityTitle) {if (dataset = null) | (renderer = Null) | (types = null) | (dataset. getSeriesCount ()! = Types. length) {throw new IllegalArgumentException ("Datasets, renderers and types shocould be not null and the datasets series count shocould 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 I Ntent;} public static final Intent events (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 int Ent;} 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 voi D checkParameters (XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer) {if (dataset = null) | (renderer = null) | (dataset. getSeriesCount ()! = Renderer. getSeriesRendererCount () {throw new IllegalArgumentException ("Dataset and renderer shocould be not null and shocould 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 shocould be not null and the dataset number of items shocould 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 shocould be not null and the dataset number of items shocould 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 ;}}