Android-made curves, histograms, pie charts, etc.-Using achartengine

Source: Internet
Author: User

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:

//Creating Categoryseries ComponentsCategoryseries series=Newcategoryseries ("First quarter sales Analysis"); Series.add ("January"),30000); Series.add ("February"),40000); Series.add ("March"),36000);//Creating Defaultrenderer ComponentsDefaultrenderer renderer =Newdefaultrenderer (); Renderer.setmargins (New int[] {20, 30, 0});//set the indirect unit between legends as PXRenderer.setlabelstextsize (15);//set the font size for a labelRenderer.setlegendtextsize (15);//set the font size of the legendSimpleseriesrenderer R1 =Newsimpleseriesrenderer (); R1.setcolor (Color.Blue); Renderer.addseriesrenderer (R1) ;//Set the pie chart color, JanuarySimpleseriesrenderer r2 =Newsimpleseriesrenderer (); R1.setcolor (Color.green); Renderer.addseriesrenderer (r2) ;//Set the pie chart color, FebruarySimpleseriesrenderer R3 =Newsimpleseriesrenderer (); R1.setcolor (color.red); Renderer.addseriesrenderer (R3) ;//Set the pie chart color, March//Generate pie chartGraphicalview 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

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.