第一步添加依赖
根据GItHub上项目的提示,在project的build.gradle中的allprojects代码块中添加如下代码
repositories {
maven { url 'https://jitpack.io' }
}
在app的build.gradle中添加如下代码
dependencies {
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
}
第二步添加Layout布局
柱形图
在需要柱形图的地方添加BarChart
<com.github.mikephil.charting.charts.BarChart
android:id="@+id/bar_chart"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
在Activity或者Fragment中设置柱形图样式
barChart = findViewById(R.id.bar_chart);
barChart.setOnChartValueSelectedListener(this);//传入this,让当前Activity实现监听回调接口
barChart.setDrawBarShadow(false);//设置柱形图阴影
barChart.setDra