代码之家  ›  专栏  ›  技术社区  ›  gaurang

如果饼图中的值为0%,如何删除行

  •  4
  • gaurang  · 技术社区  · 9 年前

    MPAndroidChart 库中,任何数据或多个数据的值可能包含0%,我正在使用piechart以外的值显示 setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE) .

    public class CustomPercentFormatter implements IValueFormatter {    
    
        private DecimalFormat mFormat;
    
        public CustomPercentFormatter() {
            mFormat = new DecimalFormat("###,###,##0.0");
        }
    
        public CustomPercentFormatter(DecimalFormat format) {
            this.mFormat = format;
        }
    
        @Override
        public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
    
            if (value == 0.0f)
                return "";
    
            return mFormat.format(value) + " %";
        }
    }
    

    但是如果我使用lines选项,那么该行显示为0%值,并且重叠显示为多个0%值,那么有人能帮我吗 ?

    image

    2 回复  |  直到 8 年前
        1
  •  3
  •   PEHLAJ Katherine    8 年前

    我改变了方法 drawValues 在里面 PieChartRenderer

    如果值为0,则不显示行。

    if (entry.getValue() != 0.0) {
        if (dataSet.getValueLineColor() != ColorTemplate.COLOR_NONE) {
            c.drawLine(pt0x, pt0y, pt1x, pt1y, mValueLinePaint);
            c.drawLine(pt1x, pt1y, pt2x, pt2y, mValueLinePaint);
        }
    }
    

    if (dataSet.getValueLineColor() != ColorTemplate.COLOR_NONE) {
        c.drawLine(pt0x, pt0y, pt1x, pt1y, mValueLinePaint);
        c.drawLine(pt1x, pt1y, pt2x, pt2y, mValueLinePaint);
    }
    
        2
  •  1
  •   gmetax    8 年前

    如果不想绘制这些线,则必须将该线的颜色设置为 ColorTemplate.COLOR_NONE

    https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/PieChartActivity.java#L199 你可以检查一下怎么做。