mpandroidchart

时间:2017-12-04 01:23:11

标签: android mpandroidchart

我有一个日期列表,图片上有3个日期,但图表只显示2个日期,并显示错误的位置... 如何显示所有日期,以及如何使X集中在正确的位置? (根据y值)

enter image description here

for(treino in treinoList) {
            entries.add(Entry(treino.data.toFloat(), treino.treinoTipo.toFloat()))
        }

        val desc = Description()
        desc.text = ""
        val dataSet = LineDataSet(entries, "Tempo/Treinos")

        val lineData = LineData(dataSet)
        chart.setNoDataText("Nenhum treino computado")
        chart.setDrawBorders(false)
        chart.data = lineData
        chart.description = desc
        chart.setGridBackgroundColor(R.color.graphGride)
        chart.setDrawGridBackground(false)
        chart.legend.textColor = ActivityCompat.getColor(this, R.color.graphLabel)
        chart.axisLeft.gridColor = ActivityCompat.getColor(this, R.color.graphLabel)
        chart.xAxis.position = XAxis.XAxisPosition.BOTTOM
        chart.xAxis.textColor = ActivityCompat.getColor(this, R.color.graphLabel)
        chart.xAxis.axisLineColor = ActivityCompat.getColor(this, R.color.graphLabel)
        chart.xAxis.setCenterAxisLabels(true)
        chart.xAxis.labelCount = treinoList.size
        chart.xAxis.valueFormatter = object : IAxisValueFormatter{
            val dateFormat = SimpleDateFormat("dd/MM", Locale.getDefault())

            override fun getFormattedValue(value: Float, axis: AxisBase?): String {
                return dateFormat.format(value)
            }
        }
        chart.axisLeft.textColor = ActivityCompat.getColor(this, R.color.graphLabel)
        chart.axisLeft.labelCount = 4
        chart.axisLeft.axisLineColor = ActivityCompat.getColor(this, R.color.graphLabel)
        chart.axisRight.setDrawLabels(false)
        chart.animateX(500)
        chart.invalidate()

1 个答案:

答案 0 :(得分:0)

从代码中删除以下行:

chart.xAxis.setCenterAxisLabels(true)
chart.xAxis.labelCount = treinoList.size