如何设置Piechart元素的自定义颜色 [英] How to set custom color for Piechart element

查看:379
本文介绍了如何设置Piechart元素的自定义颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的android项目中使用MPChart libarary。
我有Json,其中包含标签,值和颜色的饼图生成。
我想设置相同的颜色从json到饼图元素。
我按照MPChart文档,但没有找到任何解决方案用于饼图颜色设置。

I am using MPChart libarary in my android project. I have Json which contain label,value and color for pie chart generation. I want to set same color from json to piechart element. I followed MPChart documentation,But not found any solution for piechart color setting.

推荐答案

在文档中?
我建议您仔细查看

有许多其他方法可以设置 DataSet 的颜色:

There are many other ways for setting colors for a DataSet:


  • setColors(int [] colors,Context c):设置此DataSet前应使用的颜色。一旦DataSet表示的条目数大于colors数组的大小,就会重新使用颜色。你可以使用new int [] {R.color.red,R.color.green,...}为这个方法提供颜色。在内部,颜色使用 getResources()。getColor(...)来解析。

  • setColors / code>:设置应该在此DataSet之前使用的颜色。一旦DataSet表示的条目数大于colors数组的大小,就会重新使用颜色。确保颜色已准备好(在将它们添加到DataSet之前调用 getResources()。getColor(...))。

  • setColors(ArrayList< Integer> colors):设置应该在此DataSet之前使用的颜色。一旦DataSet表示的条目数大于colors数组的大小,就会重新使用颜色。确保颜色已经准备好了(通过调用getResources()。getColor(...)),然后再将它们添加到DataSet。

  • setColor ):设置应该用于此DataSet的一个和唯一的颜色。在内部,这会重新创建colors数组并添加指定的颜色。

  • setColors(int [] colors, Context c): Sets the colors that should be used fore this DataSet. Colors are reused as soon as the number of Entries the DataSet represents is higher than the size of the colors array. You can use "new int[] { R.color.red, R.color.green, ... }" to provide colors for this method. Internally, the colors are resolved using getResources().getColor(...).
  • setColors(int [] colors): Sets the colors that should be used fore this DataSet. Colors are reused as soon as the number of Entries the DataSet represents is higher than the size of the colors array. Make sure that the colors are already prepared (by calling getResources().getColor(...)) before adding them to the DataSet.
  • setColors(ArrayList<Integer> colors): Sets the colors that should be used fore this DataSet. Colors are reused as soon as the number of Entries the DataSet represents is higher than the size of the colors array. Make sure that the colors are already prepared (by calling getResources().getColor(...)) before adding them to the DataSet.
  • setColor(int color): Sets the one and ONLY color that should be used for this DataSet. Internally, this recreates the colors array and adds the specified color.

这篇关于如何设置Piechart元素的自定义颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆