1.添加依赖
在Project即工程下的build.gradle文件里添加 maven { url "https://jitpack.io" }
添加下来是这个样子的:
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
google() }
}
然后在项目下的build.gradle文件里添加 compile 'com.github.PhilJay:MPAndroidChart:v3.0.1'
2.在布局中添加
<com.github.mikephil.charting.charts.PieChart
android:id="@+id/piechart"
android:layout_width="match_parent"
android:layout_height="match_parent" />
3.activity中添加
//设置各区块的颜色 public static final int[] PIE_COLORS = { Color.rgb(181, 194, 202), Color.rgb(129, 216, 200), Color.rgb(241, 214, 145), Color.rgb(108, 176, 223), Color.rgb(195, 221, 155), Color.rgb(251, 215, 191), Color.rgb(237, 189, 189), Color.rgb(172, 217, 243) }; //设