Setting the pie slice colors in MPAndroidChart

前端 未结 4 476
离开以前
离开以前 2021-01-13 08:09

I need to define specific hex values for each slice in my pie chart.

I\'m following the wiki but the method doesn\'t seem to be working for PieDataSet

4条回答
  •  梦谈多话
    2021-01-13 09:04

    use ContextCompat.getColor(context, R.color.green1) instead of R.color.green1 if not colors will not shown properly.

    example code in Kotlin :

     val colorFirst = context?.let { ContextCompat.getColor(it, R.color.colorFirst) }
     val colorSecond = context?.let { ContextCompat.getColor(it, R.color.colorSecond) }
     val colorThird = context?.let { ContextCompat.getColor(it, R.color.colorThird) }
    
     pieDataSet.colors = mutableListOf(colorFirst, colorSecond, colorThird)
    

提交回复
热议问题