MPAndroidChart:在堆叠的条形图中隐藏0个值标签 [英] MPAndroidChart: Hide 0 value labels in a stacked bar chart
本文介绍了MPAndroidChart:在堆叠的条形图中隐藏0个值标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用MPAndroidChart显示包含两个数据集(收入和支出)的堆积条形图.当值为0时,标签与其他x轴值重叠时出现问题.
I am using MPAndroidChart to show a stacked bar chart containing two sets of data (Income and Expenditure). I'm having an issue when the value is 0 the label overlap other x axis values.
在屏幕快照的情况下,您可以看到具有值的条在以下日期具有重叠的值:14/4、15/4和16/4.
In the case of the screenshot you can see that the bars which have values have overlapping values for the following dates: 14/4, 15/4 and 16/4.
如何隐藏0值以停止重叠问题?> pp
How can I hide the 0 values to stop the overlapping issue?
推荐答案
使用IValueFormatter
界面.
示例:
public class MyValueFormatter implements IValueFormatter {
private DecimalFormat mFormat;
public MyValueFormatter() {
mFormat = new DecimalFormat("###,###,##0.00");
}
@Override
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
if(value > 0) {
return mFormat.format(value);
} else {
return "";
}
}
}
将其设置为图表数据:
barData.setValueFormatter(new MyValueFormatter());
还请检查 文档 .
Also check the documentation.
这篇关于MPAndroidChart:在堆叠的条形图中隐藏0个值标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文