Mpandroidchart
1. Many times in the project to analyze the data to use the chart, on GitHub there are a lot of good chart Open Source Library, here is a brief introduction to Mpandroidchart.
He can realize the drag of the chart, the local view, the data dynamic display and other functions
Code download: Download
2. Paste some out:
Linechart
Filling type Linechart
Linechart of a single line
Barchart2d
Barchart3d
Piechart
Scatterchart
3. Use the method to download the library on Gihub: Https://github.com/PhilJay/MPAndroidChart
When you look at the sample it gives, the project may go wrong, and here's the problem of environment coding, and changing to Utf-8 is OK.
in XML
1 < Com.github.mikephil.charting.charts.PieChart 2 Android:id = "@+id/spread_pie_chart" 3 android:layout_width= "Match_parent"4 android:layout_height = "320dip" />
In activity
Initialization
1 colortemplate mCt;2MCt =Newcolortemplate ();3Mct.adddatasetcolors (Colortemplate.pastel_colors, This);4Mchart =(Piechart) Headview.findviewbyid (R.id.spread_pie_chart);5 mchart.setcolortemplate (mCt);6Mchart.setdescription ("");7 Mchart.setholeradius (30f);8 Mchart.settransparentcircleradius (0f);9 mchart.setcentertextsize (18f);TenMchart.setdrawxvalues (true); OneMchart.setusepercentvalues (true); AMchart.setdrawlegend (false); - //space between slices - Mchart.setslicespace (1f); theMchart.setdrawholeenabled (false); -Mchart.settouchenabled (false);
Data:
1Arraylist<entry> yvals =NewArraylist<entry>();2Arraylist<string> xvals =NewArraylist<string>();3 for(inti = 0; I < listdatas.size (); i++) {4Yvals.add (NewEntry ((float) Listdatas.get (i). Getprovincecount (), i));5 Xvals.add (Listdatas.get (i). Getprovincename ());6 }7DataSet Set1 =NewDataSet (Yvals, "Content");8Arraylist<dataset> dataSets =NewArraylist<dataset>();9 Datasets.add (SET1);TenChartData data =NewChartData (xvals, dataSets); OneMchart.setdata (data);
Where Listdata is the data source in your project.
Mpandroidchart of Android Excellent chart library