效果图如下:
一、导入MPAndroidChart
repositories {
maven {
url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
}
二、布局中使用BarChart
<com.github.mikephil.charting.charts.BarChart
android:layout_width="match_parent"
android:layout_height="207dp"
android:id="@+id/chart"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:background="#ffffff"/>
三、设置图表样式
private void initChart() {
//不展示图表描述信息
barChart.getDescription().setEnabled(false);
//所有值均绘制在其条形顶部上方
barChart.setDrawValueAboveBar(false);
//纵坐标不