MPAndroidChart開(kāi)源圖表庫(kù)之餅狀圖
為大家介紹一款圖標(biāo)開(kāi)源庫(kù)MPAndroidChart,它不僅可以在Android設(shè)備上繪制各種統(tǒng)計(jì)圖表,而且可以對(duì)圖表進(jìn)行拖動(dòng)和縮放操作,用起來(lái)非常靈活。MPAndroidChart同樣擁有常用的圖表類型:線型圖、餅圖、柱狀圖和散點(diǎn)圖。
mpandroidchartlibrary.jar包下載地址:
https://github.com/PhilJay/MPAndroidChart/releases
下面主要實(shí)現(xiàn)以下餅狀圖:
1.從上面的地址中下載最新mpandroidchartlibrary-2-0-8.jar包, 然后copy到項(xiàng)目的libs中
2. 定義xml文件

3. 主要Java邏輯代碼如下。
importjava.util.ArrayList; importcom.github.mikephil.charting.charts.PieChart; importcom.github.mikephil.charting.components.Legend; importcom.github.mikephil.charting.components.Legend.LegendPosition; importcom.github.mikephil.charting.data.Entry; importcom.github.mikephil.charting.data.PieData; importcom.github.mikephil.charting.data.PieDataSet; import android.support.v7.app.ActionBarActivity; importandroid.graphics.Color; importandroid.os.Bundle; importandroid.util.DisplayMetrics; public class MainActivity extends ActionBarActivity { privatePieChartmChart; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mChart = (PieChart) findViewById(R.id.spread_pie_chart); PieDatamPieData = getPieData(4, 100); showChart(mChart, mPieData); } private void showChart(PieChartpieChart, PieDatapieData) { pieChart.setHoleColorTransparent(true); pieChart.setHoleRadius(60f); //半徑pieChart.setTransparentCircleRadius(64f); // 半透明圈//pieChart.setHoleRadius(0) //實(shí)心圓pieChart.setDescription("測(cè)試餅狀圖"); // mChart.setDrawYValues(true); pieChart.setDrawCenterText(true); //餅狀圖中間可以添加文字pieChart.setDrawHoleEnabled(true); pieChart.setRotationAngle(90); // 初始旋轉(zhuǎn)角度// draws the corresponding description value into the slice // mChart.setDrawXValues(true); // enable rotation of the chart by touch pieChart.setRotationEnabled(true); // 可以手動(dòng)旋轉(zhuǎn)// display percentage values pieChart.setUsePercentValues(true); //顯示成百分比// mChart.setUnit("
主站蜘蛛池模板:
望城县|
宁化县|
开江县|
民和|
英山县|
达孜县|
吴堡县|
徐州市|
北海市|
资源县|
柳河县|
漳浦县|
SHOW|
台中市|
应用必备|
高雄县|
五家渠市|
天门市|
玛纳斯县|
阳新县|
宜黄县|
哈密市|
武汉市|
桑日县|
闵行区|
建水县|
马尔康县|
承德市|
郎溪县|
清新县|
德格县|
吴堡县|
宜章县|
玉门市|
营口市|
望江县|
定兴县|
宕昌县|
巴楚县|
清苑县|
海门市|