:
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