问题描述
我正在制作一个饼图,为此,我正在使用 MPAndroidChart 库,该值可能包含0%的任何数据或多个数据,并且我正在使用setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE)
在饼图之外显示值.我不想在饼图中显示0%的值,但我找到了一种解决方案,可以使用格式化的值.
I'm working on a pie chart, for that, i'm using MPAndroidChart library, the values may contain 0% for any data or more than one data and I'm displaying values outside of piechart using setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE)
.I don't want to display 0% values in a pie chart, I got a solution for that to use value formatted.
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%值的行选项吗?
But if I'm using lines option then the line is displayed for 0 % values and overlapping for multiple 0% values, so can anyone help me to remove line option for 0% values?
推荐答案
我在 PieChartRenderer
类中更改了方法 drawValues
.
I changed the method drawValues
in PieChartRenderer
class.
如果值为0,则不显示行.
Do not display line if value is 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);
}
这篇关于如果饼图中的值为0%,如何删除线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!