简体   繁体   English

如何为饼图中的每个切片添加自定义颜色?

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

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.我知道我可以将布尔值设置为 true 以添加不同的颜色,这似乎是为每个切片添加不同颜色的唯一方法。

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.我想为每个切片设置不同的颜色,但不是 apache poi 给出的默认颜色。

You need to create un dataset to change the color, this is an example您需要创建 un 数据集来更改颜色,这是一个示例

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()
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM