Reputation:
I try to set color in PieChart of MPAndroidChart.But its not set it.I want to add custom color in my partition . Here is my code :-
fun setupPieChartView() {
mPie = findViewById(R.id.piechart)
mPie?.setUsePercentValues(true)
val desc: Description = Description()
desc.text = "PieChart"
mPie?.description = desc
val legend: Legend? = mPie?.legend
legend?.horizontalAlignment = Legend.LegendHorizontalAlignment.LEFT
val value = Arrays.asList(trueAns.toFloat(), wrongAns.toFloat(), noAns.toFloat())
val label = Arrays.asList("True", "false", "Not")
val entry = ArrayList<PieEntry>()
for (i in value.indices) {
entry.add(PieEntry(value.get(i), label.get(i)))
}
val dataSet = PieDataSet(entry, "Result")
dataSet.setDrawValues(true)
val pieData = PieData(dataSet)
pieData.setValueFormatter(PercentFormatter())
pieData.setValueTextSize(10f)
pieData.setValueTextColor(Color.WHITE)
mPie?.data = pieData
}
Upvotes: 0
Views: 3342
Reputation: 13027
Instead of this
dataSet.colors = ColorTemplate.COLORFUL_COLORS.toList()
it should be
dataSet.setColors(Color.RED, Color.GREEN, Color.BLUE);
Because first one gives default colors, that's why you can't override colors. Here is result of your code :
Upvotes: 2