欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

AndroidMPAndroidChart開源圖表庫之如何實現(xiàn)餅狀圖

這篇文章主要介紹Android MPAndroidChart開源圖表庫之如何實現(xiàn)餅狀圖,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!

高港網(wǎng)站建設公司創(chuàng)新互聯(lián)公司,高港網(wǎng)站設計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為高港成百上千提供企業(yè)網(wǎng)站建設服務。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站制作要多少錢,請找那個售后服務好的高港做網(wǎng)站的公司定做!

MPAndroidChart是一款基于Android的開源圖表庫,MPAndroidChart不僅可以在Android設備上繪制各種統(tǒng)計圖表,而且可以對圖表進行拖動和縮放操作,應用起來非常靈活。MPAndroidChart同樣擁有常用的圖表類型:線型圖、餅圖、柱狀圖和散點圖。

下面主要實現(xiàn)以下餅狀圖:

1.從上面的地址中下載最新mpandroidchartlibrary-2-0-8.jar包, 然后copy到項目的libs中;

2.定義xml文件;

3.主要Java邏輯代碼如下,注釋已經(jīng)都添加上了。

package com.jackie.mpandroidpiechart; 
import java.util.ArrayList; 
import com.github.mikephil.charting.charts.PieChart; 
import com.github.mikephil.charting.components.Legend; 
import com.github.mikephil.charting.components.Legend.LegendPosition; 
import com.github.mikephil.charting.data.Entry; 
import com.github.mikephil.charting.data.PieData; 
import com.github.mikephil.charting.data.PieDataSet; 
import android.support.v7.app.ActionBarActivity; 
import android.graphics.Color; 
import android.os.Bundle; 
import android.util.DisplayMetrics; 
public class MainActivity extends ActionBarActivity { 
 private PieChart mChart; 
 @Override 
 protected void onCreate(Bundle savedInstanceState) { 
 super.onCreate(savedInstanceState); 
 setContentView(R.layout.activity_main); 
 mChart = (PieChart) findViewById(R.id.spread_pie_chart); 
 PieData mPieData = getPieData(4, 100); 
 showChart(mChart, mPieData); 
 } 
 private void showChart(PieChart pieChart, PieData pieData) { 
 pieChart.setHoleColorTransparent(true); 
 pieChart.setHoleRadius(60f); //半徑 
 pieChart.setTransparentCircleRadius(64f); // 半透明圈 
 //pieChart.setHoleRadius(0) //實心圓 
 pieChart.setDescription("測試餅狀圖"); 
 // mChart.setDrawYValues(true); 
 pieChart.setDrawCenterText(true); //餅狀圖中間可以添加文字 
 pieChart.setDrawHoleEnabled(true); 
 pieChart.setRotationAngle(90); // 初始旋轉角度 
 // draws the corresponding description value into the slice 
 // mChart.setDrawXValues(true); 
 // enable rotation of the chart by touch 
 pieChart.setRotationEnabled(true); // 可以手動旋轉 
 // display percentage values 
 pieChart.setUsePercentValues(true); //顯示成百分比 
 // mChart.setUnit(" ?"); 
 // mChart.setDrawUnitsInChart(true); 
 // add a selection listener 
// mChart.setOnChartValueSelectedListener(this); 
 // mChart.setTouchEnabled(false); 
// mChart.setOnAnimationListener(this); 
 pieChart.setCenterText("Quarterly Revenue"); //餅狀圖中間的文字 
 //設置數(shù)據(jù) 
 pieChart.setData(pieData); 
 // undo all highlights 
// pieChart.highlightValues(null); 
// pieChart.invalidate(); 
 Legend mLegend = pieChart.getLegend(); //設置比例圖 
 mLegend.setPosition(LegendPosition.RIGHT_OF_CHART); //最右邊顯示 
// mLegend.setForm(LegendForm.LINE); //設置比例圖的形狀,默認是方形 
 mLegend.setXEntrySpace(7f); 
 mLegend.setYEntrySpace(5f); 
 pieChart.animateXY(1000, 1000); //設置動畫 
 // mChart.spin(2000, 0, 360); 
 } 
 /** 
 * 
 * @param count 分成幾部分 
 * @param range 
 */ 
 private PieData getPieData(int count, float range) { 
 ArrayList<String> xValues = new ArrayList<String>(); //xVals用來表示每個餅塊上的內容 
 for (int i = 0; i < count; i++) { 
 xValues.add("Quarterly" + (i + 1)); //餅塊上顯示成Quarterly1, Quarterly2, Quarterly3, Quarterly4 
 } 
 ArrayList<Entry> yValues = new ArrayList<Entry>(); //yVals用來表示封裝每個餅塊的實際數(shù)據(jù) 
 // 餅圖數(shù)據(jù) 
 /** 
 * 將一個餅形圖分成四部分, 四部分的數(shù)值比例為14:14:34:38 
 * 所以 14代表的百分比就是14% 
 */ 
 float quarterly1 = 14; 
 float quarterly2 = 14; 
 float quarterly3 = 34; 
 float quarterly4 = 38; 
 yValues.add(new Entry(quarterly1, 0)); 
 yValues.add(new Entry(quarterly2, 1)); 
 yValues.add(new Entry(quarterly3, 2)); 
 yValues.add(new Entry(quarterly4, 3)); 
 //y軸的集合 
 PieDataSet pieDataSet = new PieDataSet(yValues, "Quarterly Revenue 2014"/*顯示在比例圖上*/); 
 pieDataSet.setSliceSpace(0f); //設置個餅狀圖之間的距離 
 ArrayList<Integer> colors = new ArrayList<Integer>(); 
 // 餅圖顏色 
 colors.add(Color.rgb(205, 205, 205)); 
 colors.add(Color.rgb(114, 188, 223)); 
 colors.add(Color.rgb(255, 123, 124)); 
 colors.add(Color.rgb(57, 135, 200)); 
 pieDataSet.setColors(colors); 
 DisplayMetrics metrics = getResources().getDisplayMetrics(); 
 float px = 5 * (metrics.densityDpi / 160f); 
 pieDataSet.setSelectionShift(px); // 選中態(tài)多出的長度 
 PieData pieData = new PieData(xValues, pieDataSet); 
 return pieData; 
 } 
}

 效果圖如下:

Android MPAndroidChart開源圖表庫之如何實現(xiàn)餅狀圖

主要是一些基本屬性和API的調用,具體每個API都有什么樣的效果和作用,只能靠自己去嘗試。后面還會陸陸續(xù)續(xù)為大家介紹MPAndroidChart其他類型的圖表。

以上是“Android MPAndroidChart開源圖表庫之如何實現(xiàn)餅狀圖”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

本文題目:AndroidMPAndroidChart開源圖表庫之如何實現(xiàn)餅狀圖
標題URL:http://www.aaarwkj.com/article0/peggio.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供定制開發(fā)域名注冊、網(wǎng)站制作網(wǎng)站營銷、響應式網(wǎng)站自適應網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

h5響應式網(wǎng)站建設
日本东京一区二区三区| 91国内外精品自在线播放| 亚洲欧美一区二区中文字幕| 国产精品一区二区污网站| 欧美日韩一区二区三区久久精品| 美女床上激情啪啪网页| 欧美夫妻香蕉视频网站| 国产一区二区在线乱码| 免费在线观看性生活视频| 中文字幕中文字幕乱码| dy888午夜福利精品国产97| 国产精品久久午夜伦鲁鲁| 国产精品成人一区二区三| 国产一区二区三区在线观看俏佳人| 日本在线精品在线观看| 欧美久久精品在线观看| 公侵犯人妻中文字幕一区| 黄色大片免费在线观看| 日韩免费的黄色片网站| 中文字幕色视频在线观看| 大陆av剧情网站在线观看| 91精品人妻互换一区二区| 日韩在线中文字幕三区| 亚洲欧美精品福利在线| 乱码人妻精品一区二区三区| 亚洲老熟女老妇老女人| 国产999精品免费国产| 日吊视频在线免费观看| 2020亚洲欧美日韩在线| 亚洲精品国产熟女av| 91亚洲蜜臀精品国产| 亚洲精品在线播放av| 亚洲国产区男人的天堂| 国产亚洲一区二区三区乱码| 日本97久久久久久精品| 毛片精品一区二区二区三区| 中文字幕日日夜夜av| 日本伦理三级在线观看| 粉嫩美女精品一区二区| 日韩少妇人妻一区二区| 国产欧美一区二区三区久久|