Android Achartengine Learning

Source: Internet
Author: User
Tags polyline

I. General introduction ofAchartengine

achartengine : Each chart requires a dataset (dataset) and a renderer set (Renderer);

-- Data set : Also made up of many data

-- renderer : Also made up of different sub-renderers

-- get activity or component : the Chart factory (chartfactory) can generate graphicalview with graphs or Graphicalac by calling datasets (datasets) and renderer collections (Renderer) Tivity

For example, a chart factory (Chartfactory) creates a intent of a line chart by passing data from the data set (DataSet) and renderer collection (Renderer).

Intent Intent = chartfactory.getlinechartintent (context,dataset,renderer);

650) this.width=650; "src=" Http://www.th7.cn/d/file/p/2014/08/16/21d8f6e253d9149405e91b835f222152.png "/>

Second, Achartengine related class introduction

--Xymultipleseriesdataset: A DataSet that encapsulates the data needed for a chart and needs to include xyseries in this data set

-xyseries: part of the chart dataset, each representing a data set such as a polyline, a chart can have more than one line, all the data together is the data set Xymultipleseriesdataset;

--Xymultipleseriesrenderer: renderer set, renderer for multiple curves in the chart;

--Xyseriesrenderer: a single curve or unit renderer, one chart may have multiple curves or bars, each of which requires a renderer, and all renderers together are the renderer set Xymultipleseriesrendere R

Three, achartengine main code parsing

1. Graph Histogram Chart Data set

(1) for x y-axis data is Double

Related class Description:

--Xymultipleseriesdataset class: This class can encapsulate data sets of graphs such as graph histogram, the generality of which is that the values are composed of x and Y values, which need to be passed into the x-axis data and y-axis data separately;

--Xyseries class: There are multiple curves in the chart, which encapsulates a collection of individual curves, and xymultipleseriesdataset encapsulates multiple xyseries;

Data that needs to be prepared:

--Single set of data name collection: string[] titles, single-group data names each curve may have a name, and a chart may have multiple curves, so a header array is needed here;

--X-axis data set: List<double[]> xValues, x-axis data set, where each array is the x-axis data of a curve, and the entire List set is the data of multiple curves;

--y-axis data set: list<double[]> yvalues, y-axis data set, the entire List set is the y-axis data set for multiple curves;

The relevant method is detailed:

--Create a Xymultipleseriesdataset object: Call the parameterless constructor directly, Xymultipleseriesdataset DataSet = new Xymultipleseriesdataset ();

--Create a Xyseries object: The object is a single curve data, you can set a single curve title, x-axis data array, y-axis data array, Xyseries series = new Xyseries (String titles, float scale );

--Add data for a single curve: The Xyseries object adds two arrays, respectively, the x-axis and y-axis data, Series.add (Xv[k], yv[k]);

--Add the Xyseries object to the Xymultipleseriesdataset object: Dataset.addseries (series);

(2) The x-axis is the date y-axis is Double

Related class Description:

--Xymultipleseriesdataset: This kind of date-value graph, the chart dataset used is also the class;

--TimeSeries: This is different, because the data of a single curve is to encapsulate the Date array, so we use the class to encapsulate date[] and double[] data;

Data that needs to be prepared:

--string[] titles: There are multiple polylines in the chart, and each element in the array is the title of a polyline;

--Each date[in the list<date[]> xvalues:list set is the x-axis data of a curve;

--list<double[]> yvalues:list each double[] in the collection is the y-axis data of a curve;

Description of the relevant methods:

--Create a single curve data TimeSeries object: TimeSeries series = new TimeSeries (Titles[i]), the parameter is the title name of the curve;

--Set the date and value array to the TimeSeries object: Series.add (Xv[k], yv[k]);

--Set the TimeSeries object to the Xymultipleseriesdataset object: Dataset.addseries (series);

2. Graph Graph Renderer

(1) Curve rendering

Related class Description:

--Xymultipleseriesrenderer: The overall graph renderer, which encapsulates many xyseriesrenderer single-curve renderers;

--Xyseriesrenderer: A single curve renderer that sets the color and style of the curve;

Data preparation:

--int[] Colors: Color set, each curve must have a color value;

--pointstyle[] styles: A collection of curve styles, each with its own drawing style;

Xymultipleseriesrenderer Related Method Introduction:

--Set XY axis title font size: setaxistitletextsize (int size);

--Set table header size: setcharttitletextsize (int size);

--Set Label text size: setlabelstextsize (int size);

--Set Description text size: setlegendtextsize (int size);

--Set the size of the point: setpointsize (int size);

--Add a single curve renderer: Addseriesrenderer (render);

Xyseriesrenderer Related Method Introduction:

--Create object: Xyseriesrenderer r = new Xyseriesrenderer ();

--Set individual curve color: R.setcolor (colors[i]);

--Set individual curve drawing style: R.setpointstyle (styles[i]);

(2) axis settings

Renderer parameter setting: The axis rendering is mainly a series of parameter setting for Xymultipleseriesrenderer, which is the method of calling the Xymultipleseriesrenderer object;

--Set the curve title: Setcharttitle (String tittle);

--Set X axis title: Setxtitle (String tittle);

--Set Y axis title: setytitle (String tittle);

--Set X-axis minimum: setxaxismin (double);

--Set X axis maximum: Setxaxismax (double);

--Set the y-axis minimum value: Setyaxismin (double);

--Set Y-axis maximum: Setyaxismax (double);

--Set axis color: Setaxescolor ();

--Set Label color: Setlabelscolor ();

3. Pie chart Data Set

(1) Single pie chart dataset

Related class Description:

--Categoryseries: Pie chart data set;

Description of the relevant methods:

--Add Data elements: Categoryseries.add (String category, double value), with the arguments being names and values, respectively;

(2) Multi-pie chart data set

Related class Description:

--multiplecategoryseries: Multi-pie chart dataset, which has no relationship with the Categoryseries object of the single pie chart dataset;

Prepare the data:

--Pie chart Each element name: list<string[]> titles, where the array in the collection is a collection of each element of a pie chart;

--the size of each element of the pie chart: list<double[]> values, where the array is the size of each element of a pie chart;

Description of the relevant methods:

--Create a multi-pie chart DataSet: Multiplecategoryseries series = new Multiplecategoryseries (title), the name of the incoming chart;

--Add a pie chart of data: Series.add (tittle, titles.get (k), value), the first argument is a single pie chart name, the second argument is a pie chart element name string array, and the third is the pie chart element size double[] Number Group

4. Pie chart Renderer

Related class Description:

--Defaultrenderer: Pie chart renderer, single pie chart and multi-pie chart renderer used are all the same;

--Defaultrenderer: Pie chart single element renderer, a pie chart has more than one renderer rendered, and the entire chart has multiple sets of the renderer;

Data preparation:

--Pie chart element color: int[] colors, all the colors in the pie chart are placed in an array, each element has a color;

Defaultrenderer class Method Description:

--Construction Method: Defaultrenderer renderer = new Defaultrenderer ();

--Set Label text size: setlabelstextsize (int size);

--Set Description text size: setlegendtextsize (int size);

--Set margin: SetMargins (new int[] {20, 30, 15, 0});

--Add the Simpleseriesrenderer object to the Renderer collection: Addseriesrenderer (R);

Simpleseriesrenderer Method:

--Constructor: Simpleseriesrenderer r = new Simpleseriesrenderer ();

--Set color: setcolor (color);

5. Column Chart Datasets

Related class Description:

--Xymultipleseriesdataset: Encapsulates the data of a histogram, which may have multiple histograms, each encapsulating several categoryseries individual data set objects;

-Categoryseries: Data from a single histogram in a histogram can be encapsulated into a xymultipleseriesdataset data set;

Data preparation:

--Histogram title: string[] titles, because there may be multiple bars in a histogram chart, a string array is required to hold the headings;

--Histogram value: list<double[]> values, each array in the collection represents the value of a bar chart;

Categoryseries Method Description:

--Constructor: Categoryseries series = new Categoryseries (Titles[i]), the passed parameter is the value of the histogram;

--Set the value size: Series.add (double), the specific value needs one to go to set;

--Conversion type: Series.toxyseries (), only converted to Xyseries object, can be added to the Xymultipleseriesdataset object;

6. Bar Chart Renderer

Related class Description:

--Xymultipleseriesrenderer: The histogram renderer set is the same as the renderer of the graph, which encapsulates a lot of simpleseriesrenderer objects;

--Simpleseriesrenderer: A single histogram renderer in a histogram that can be encapsulated into a Xymultipleseriesrenderer object;

Prepare the data:

--Histogram color: int[] Colors, a histogram chart contains a number of bars, each histogram set a color;



This article is from the "Program Ape Advanced Siege Lion" blog, please be sure to keep this source http://zhoum1118.blog.51cto.com/10054110/1649975

Android Achartengine Learning

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.