折线图上x轴的值错误

时间:2018-11-10 19:08:51

标签: android kotlin mpandroidchart

我在android应用程序中使用MPAndroidChart,但是x轴格式错误,并且标签重复。这是我的代码

private fun lineChart(exams: List<Exam>) {
        val formatter: DateFormat = SimpleDateFormat("dd/MM/yyyy")

        val lineChart: LineChart = linechart
        lineChart.animateY(1000)
        val d = Description()
        d.text = "TEST"
        lineChart.description = d

        val yValues: ArrayList<Entry> = ArrayList()
        var count = 0
        for (exam in exams.sortedByDescending { exam -> exam.date }) {
            if (getString(R.string.scores_array_admitted) != exam.score)
                yValues.add(Entry(count++.toFloat(), exam.score.toFloat()))
        }

        val lineDataSet = LineDataSet(yValues, getString(R.string.linechart_score_label))
        val dataSet: ArrayList<ILineDataSet> = ArrayList()
        dataSet.add(lineDataSet)

        val lineData = LineData(dataSet)

        val xAxis: XAxis = lineChart.xAxis

        val values = ArrayList<String>()
        for (exam in exams.sortedByDescending { exam -> exam.date }) {
            if (getString(R.string.scores_array_admitted) != exam.score)
                values.add(formatter.format(exam.date))
        }

        val array = arrayOfNulls<String>(values.size)
        values.toArray(array)

        var aa = array!!


        xAxis.valueFormatter = MyAxisValueFormatter(aa)

        lineChart.data = lineData

    }

在调试中,我看到数组中的值是正确的,2次检查,在 values 数组中,标签是检查的两个日期,正好是两个,但是当我运行应用程序时结果就是这个http://documenti.camera.it/apps/commonServices/getDocumento.ashx?sezione=bollettini=comunicato=17=2016=06=14=03=data.20160614.com03.bollettino.sede00020.tit00010.int00010=data.20160614.com03.bollettino.sede00020.tit00010.int00010#data.20160614.com03.bollettino.sede00020.tit00010.int00010

在x轴上,我只有两个日期

0 个答案:

没有答案