Search code examples
pie-chartmpandroidchart

MpChartLib in Android - hide text in small slices of PieChart


How can i hide text of small slices in pie chart without to remove the text from the legend in the bottom?

I tried to remove the text like this:

    if ((yVal < 5F) {
        name = "";
    } else {
       //Add to y values
    }

But then the legent text is empty also. so the users can't really know who is this slice.


Solution

  • My solution is to separate the legend texts and the pie chart slices text.
    I set the legend (bottom map for each color) text and colors in this way
    - In loop for all the contacts:

    List<Integer> colors = new ArrayList<>();
    List<String> labels = new ArrayList<>();
    
    labels.add(fullName);
    colors.add(METRIC_COLORS[index]);
    
    Legend l = chart.getLegend();
    l.setCustom(colors, labels);
    

    In addition I added the text of pie-slices:

    PieDataSet dataSet = new PieDataSet(yVals1, "");
    dataSet.setColors(METRIC_COLORS);