0

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

}

1 Answers1

2

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 :

enter image description here

Misha Akopov
  • 12,241
  • 27
  • 68
  • 82
  • thanks but when My data like that True = 1 , False = 3, Not = 96 , my data not set properlly in Pie chart , How can i manage it? –  Jul 24 '18 at 05:42
  • Ok , but it is another question. It is not proper to edit question and put absolutely new one instead of original. Please put back initial question, because my answer looks very silly and not relevant. Open another question and copy here link, I will try to help with that one also. – Misha Akopov Jul 24 '18 at 06:08
  • Thanks, paste here link of new question whe you create, I will try to help :) – Misha Akopov Jul 24 '18 at 08:00
  • [https://stackoverflow.com/questions/51493521/manage-text-in-some-situation-piechart-of-mpandroidchart] Here is the link @Misha –  Jul 24 '18 at 08:02