我正在制作饼图,为此,我正在使用MPAndroid图表库中,任何数据或多个数据的值可能包含 0%,并且我使用饼图之外的方式显示值setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE)
。
我不想在饼图中显示 0% 值,我找到了使用值格式的解决方案。
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) + " %";
}
}
但是,如果我使用线条选项,则该线条将显示 0% 值,并重叠多个 0% 值,所以任何人都可以帮助我删除 0% 值的行选项?
我改变了方法drawValues
in PieChartRenderer
class.
如果值为 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);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)