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.
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.
How can I hide the 0 values to stop the overlapping issue?
Use the IValueFormatter
interface.
Example:
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 "";
}
}
}
Set it for the chart-data:
barData.setValueFormatter(new MyValueFormatter());
Also check the documentation.