The effect is so

First, add the following two lines to build.gradle(project)Then add the following line to build.gradle(Module) :Then add it to activity_main.xml

   <com.github.mikephil.charting.charts.BarChart
                android:id="@+id/bar_chart"
                android:layout_width="1200dp"
                android:layout_height="400dp" />
Copy the code

And then in mianActivity

import android.annotation.SuppressLint
import android.graphics.Color
import android.os.Bundle
import android.view.View.OnTouchListener
import androidx.appcompat.app.AppCompatActivity
import com.github.mikephil.charting.charts.BarChart
import com.github.mikephil.charting.components.AxisBase
import com.github.mikephil.charting.components.MarkerView
import com.github.mikephil.charting.components.XAxis
import com.github.mikephil.charting.data.BarData
import com.github.mikephil.charting.data.BarDataSet
import com.github.mikephil.charting.data.BarEntry
import com.github.mikephil.charting.formatter.IAxisValueFormatter
import kotlinx.android.synthetic.main.activity_main.*


class MainActivity : AppCompatActivity() {
    private var mBarChart: BarChart? = null
    private var mBarData: BarData? = null
    private var xValues: ArrayList<String>? = null
    var mMap = mutableMapOf<String,String>()
    override fun onCreate(savedInstanceState: Bundle?). {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        mBarChart = findViewById<BarChart>(R.id.bar_chart)
        addData()
        initData()
        setLegend()
        setXAxis()
        setMRAxis()
    }
    fun addData(a){// Make fake data
        for (x in 0.20.) {
            val y = (Math.random() * 30).toFloat()
            mMap.put("08 -" + (x + 1).toString(),y.toString())
        }
    }
    private fun initData(a) {// Initialize the data
        val yValues = java.util.ArrayList<BarEntry>()
        xValues = ArrayList()
        var count=0
        for (en inmMap){ yValues.add(BarEntry(count.toFloat(), en.value.toFloat())) xValues!! .add(en.key) count+=1
        }
        val barDataSet = BarDataSet(yValues, "Bar chart")
        barDataSet.color = Color.parseColor("#99D9BE")// Set the bar chart color value
        barDataSet.highLightColor = Color.rgb(39.211.138)// Sets the selected color value
        barDataSet.setDrawValues(false)// Do not set the number display on the bar chart
        mBarData = BarData(barDataSet)
    }

    fun setLegend(a) {// Set legendmBarChart!! .description.isEnabled =false// Do not set descriptionmBarChart!! .data= mBarData mBarChart!! .setDrawMarkers(true) mBarChart!! .setScaleEnabled(false) mBarChart!! .minOffset =1fmBarData!! .barWidth =0.2 fmBarChart!! .legend.isEnabled =false/ / set the legend
    }

    fun setXAxis(a){// Set the x axis
        valxAxis: XAxis = mBarChart!! .xAxis xAxis.position = XAxis.XAxisPosition.BOTTOM xAxis.setDrawGridLines(false)
        xAxis.textSize = 10f
        xAxis.axisLineColor = Color.parseColor("#E5E5E5")// Set the X-axis colorxAxis.labelCount = xValues!! .count() xAxis.position = XAxis.XAxisPosition.BOTTOM// At the bottom
        xAxis.setDrawGridLines(false) // Do not draw X grid lines
        xAxis.textSize = 14f // The text size is 14
        xAxis.valueFormatter = object : IAxisValueFormatter {
            override fun getFormattedValue(value: Float, axis: AxisBase): String {
                returnjava.lang.String.valueOf(xValues!! [value.toInt()]) }override fun getDecimalDigits(a): Int {
                return 0}}}private fun setMRAxis(a) {// Set the y axis
        valmRAxis = mBarChart!! .axisRight mRAxis.isEnabled =false
        valmLAxis = mBarChart!! .axisLeft mLAxis.setDrawAxisLine(false)
        mLAxis.setDrawGridLines(false) mBarChart!! .requestLayout() } }Copy the code