Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPAndroidChart - How to change the color of PieChart center Background?

Im trying to use the MPAndroidChart library to develop a circular chart. But only Pie chart is available. So i tried giving two xvalue coordinates, with one color similar to background. So i got something similar to circular chart. But i'm not able to change the background color and font color of center text inside the pie chart?

Thanks!

like image 683
Bala Avatar asked Sep 19 '14 06:09

Bala


2 Answers

To set center color:

mChart.setDrawHoleEnabled(true);
mChart.setHoleColor(...);

To set center text

mChart.setDrawCenterText(true);
mChart.setCenterText(...);
like image 161
MRK Avatar answered Sep 27 '22 22:09

MRK


There are two possible solutions:

Retrieve the Paint object used by the chart to draw the "center-hole" and modify it the way you want

Paint p1 = mChart.getPaint(Chart.PAINT_HOLE);
p1.setColor(...);

Paint p2 = mChart.getPaint(Chart.PAINT_CENTER_TEXT);
p2.setColor(...);

Or use this, if you only display one value anyway: CircleDisplay

like image 38
Philipp Jahoda Avatar answered Sep 27 '22 23:09

Philipp Jahoda