androidchartsmpandroidchart

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!


Solution

  • 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