android-with Achartengine appeased shape diagram

Source: Internet
Author: User


Code

http://download.csdn.net/detail/miaoyunzexiaobao/8386183

Steps:

1. Introduction of Achartengine Package

2. Write the drawing function: the first parameter of this function is the layout variable (where the pie chart is placed), the second argument is a double array (controls the proportions in the pie chart)

public void Drawpie (LinearLayout layout, double[] value) {int[] COLORS = new int[] {color.green, color.blue, Color.Black, Color.magenta, Color.cyan}; Categoryseries mseries = new Categoryseries ("");D efaultrenderer mrenderer = new Defaultrenderer (); Graphicalview Mchartview;mchartview = Chartfactory.getpiechartview (this, mseries, mrenderer); Layout.addView ( Mchartview, New Layoutparams (layoutparams.match_parent,layoutparams.match_parent)); Mrenderer.removeallrenderers ( ); Mseries.clear (); for (double v:value) {Mseries.add ("Series" + (Mseries.getitemcount () + 1), V); Simpleseriesrenderer renderer = new Simpleseriesrenderer () Renderer.setcolor (colors[(Mseries.getitemcount ()-1)% Colors.length]); Mrenderer.addseriesrenderer (renderer);} Mchartview.repaint ();}

3. In the OnCreate in Mainactivity, add:

Double[] Value = {10.00, 20.00, 30.00, 40.00, 50.00};D Rawpie ((linearlayout) Findviewbyid (R.id.chart), value);


The Drawpie function is detailed:

The program calls the Drawpie function in the Oncreat function to draw a pie chart in the activity.

Variable:

Categoryseries mseries: Data set

Defaultrenderer mrenderer: Chart Settings set

Graphicalview mchartview: Pie chart control

The function first places the Mchartview in the incoming linearlayout, and then resets Mrenderer and Mseries.

Then use for to traverse the incoming values. For each value, perform the following actions:

1. Add title and value to Mseries

2. Addseriesrenserer in Mrenserer

Finally redraw the Mchartview

android-with Achartengine appeased shape diagram

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.