Prior to implementing diagrams in Java development using the Jfreechar component, a small project recently required data analysis on the Android side, how to implement the chart? Check it out. Google provides an open source component Achartengine is very useful, can be used to draw a variety of graphics, fully meet the needs of development, the following is how to use.
First, the preparatory work |
Download the jar Package
Website address: http://code.google.com/p/achartengine/
Web address: Http://pan.baidu.com/s/1EYhUe (with API documentation, code)
Second, the key points explain the use of--achartengined |
1. Chartfactory Components
The Chartfactory component provides a getxxxx method to obtain different graphics, such as
Getbarchartview () Bar chart
Getpiechartview () Pie chart
Getlinechartview (Context context, Xymultipleseriesdataset DataSet, Xymultipleseriesrenderer renderer)//Line chart
Getcubelinechartview ()//Smooth curve
2, Categoryseries and Defaultrenderer
These methods generally have three parameters (the different graphs will have some additional parameters)
Context context,categoryseries DataSet, Defaultrenderer renderer
Context: Represents the application context
Categoryseries: Is the data information of the chart, including the element name and value of the composition achartengined is based on the percentage of the statistics
Defaultrenderer: Sets the style of the picture, such as setting the color, title size, background color, and so on for each element
If you are drawing a pie chart, the code is as follows:
Create the Categoryseries component Categoryseries series=new categoryseries ("First quarter sales Analysis"), Series.add ("January", 30000), Series.add ("February", 40000); Series.add ("March", 36000);//Create Defaultrenderer component Defaultrenderer renderer = new Defaultrenderer (); Renderer.setmargins (new int[] { 0});//Set the indirect unit between legends is pxrenderer.setlabelstextsize (15);// Sets the font size of the label renderer.setlegendtextsize (15);//sets the font size of the legend simpleseriesrenderer r1 = new Simpleseriesrenderer (); R1.setcolor (Color.Blue); Renderer.addseriesrenderer (R1);//Set the pie chart color, January simpleseriesrenderer r2 = new Simpleseriesrenderer (); R1.setcolor (Color.green); Renderer.addseriesrenderer (R2);//Set the pie chart color, February simpleseriesrenderer r3 = new Simpleseriesrenderer () R1.setcolor (color.red); Renderer.addseriesrenderer (R3); Set the pie chart color, March//Generate pie chart Graphicalview View=chartfactory.getpiechartview (context, series, renderer);
3, Graphicalview
These methods return the view--Graphicalview that renders the chart, which is displayed using the layout's AddView () method, such as:
Graphicalview View=chartfactory.getpiechartview (context, series, renderer); Layout.addview (Charview);
Draw other graphics steps and pie charts the same, you can combine the API document test
III. implementation of the case |
The case consists of drawing curves, histograms, and pie shapes, which are encapsulated on the basis of the achartengined component, and the core code is explained in the example above, which only provides
Source: Http://pan.baidu.com/s/1eQlJJVG
Android-made curves, histograms, pie charts, etc.-Using achartengine