How do I add custom colors to each slice in a Pie Chart?

785 views Asked by At

I know I can set a boolean to true to add varying colors, which seems to be the only way to add different colors per slice.

As far as I can see, I can only do it on the series level...which will just set every slice to one color, which is not what I want. I want to set each slice a different color, but not the default ones given by apache poi.

1

There are 1 answers

0
Alejandro Gonzalez On

You need to create un dataset to change the color, this is an example

fun setColor() {
        val entries = arrayListOf<PieEntry>()
        val colors = arrayListOf<Int>()
        for (category in 4) {
         colors.add(Color.parseColor("#FFFFFF")

        }
     val dataSet = PieDataSet(entries, "")
        dataSet.colors = colors
      val data = PieData(dataSet)
       data.setValueTextSize(11f)
      data.setValueTextColor(Color.WHITE)
      pieChart.data = data
       pieChart.highlightValues(null)
      pieChart.invalidate()
    }