MPChart绘制值自定义-水平堆叠的BarChart

时间:2019-10-01 07:10:33

标签: android mpandroidchart

我正在使用MPChart库绘制水平堆积的条形图。到目前为止,我已经根据要求实现了水平堆叠条形图的显示,但是在图表下方的自定义图例视图上用线指示器阻止了显示。我正在附上期望结果的图片,我们将不胜感激。

所需结果 Desired Result

已实现的结果 Achieved result

Desired result Achieved result

private fun setupMealtimeDistributionGraph() {
    val entries = ArrayList<BarEntry>()
    entries.add(BarEntry(0f, floatArrayOf(10f, 30f, 10f, 30f, 20f)))

    val set = BarDataSet(entries, "")
    set.colors = mutableListOf(
        ContextCompat.getColor(activity!!.applicationContext, R.color.blue_300),
        ContextCompat.getColor(activity!!.applicationContext, R.color.green_300),
        ContextCompat.getColor(activity!!.applicationContext, R.color.orange_300),
        ContextCompat.getColor(activity!!.applicationContext, R.color.indigo_200),
        ContextCompat.getColor(activity!!.applicationContext, R.color.indigo_300)
    )
    val data = BarData(set)
    data.setDrawValues(false)
    data.isHighlightEnabled = false
    mealtimeDistributionChart.data = data
    mealtimeDistributionChart.axisLeft.setDrawGridLines(false)
    mealtimeDistributionChart.xAxis.setDrawGridLines(false)
    mealtimeDistributionChart.description.isEnabled = false
    mealtimeDistributionChart.axisLeft.setDrawLabels(false)
    mealtimeDistributionChart.axisRight.setDrawLabels(false)
    mealtimeDistributionChart.xAxis.setDrawLabels(false)
    mealtimeDistributionChart.legend.isEnabled = false
    mealtimeDistributionChart.invalidate()
}

0 个答案:

没有答案