1

I am using a LineChart from MPAndroidChart and I want to implement a custom legend. When I add a label and a corresponding LegendForm with a spezific color, the chart displays the form in grey anyway.

How can I give the form the color I want?

Here is the code I use:

LegendEntry("testTest", Legend.LegendForm.SQUARE, Float.NaN, Float.NaN , null , R.color.blue)
Chinibin
  • 673
  • 1
  • 5
  • 7

1 Answers1

2

Your problem is you are passing as a parameter a color resource id (ColorRes) where you actually need a resolved color (an RGB triple or @ColorInt).

See this answer for the difference between them; in short they are both integers but one of them is an id that points to a resource like R.color.blue and another is an int that represents an RGB triple like #0000FF.

You should change your code to:

new LegendEntry("testTest", Legend.LegendForm.SQUARE, Float.NaN, Float.NaN , null , ResourcesCompat.getColor(getResources(), R.color.blue, null));
Community
  • 1
  • 1
David Rawson
  • 20,912
  • 7
  • 88
  • 124