Reputation: 1
enter image description hereI tried all methods but I could not remove the decimal from bar label. How can I remove decimal part from the bar label
barData.setValueFormatter(new ValueFormatter() {
@Override
public String getFormattedValue(float value) {
if (value > 0){
return super.getFormattedValue((int)value);
}else{
return "";
}
}
});
Upvotes: 0
Views: 546
Reputation: 567
This might be the answer:
@Override
public String getFormattedValue(float value, AxisBase axis) {
val df = DecimalFormat("#");
df.roundingMode = RoundingMode.CEILING;
return df.format(value);
}
Combining your code, it should look like this:
@Override
public String getFormattedValue(float value, AxisBase axis) {
if (value > 0) {
val df = DecimalFormat("#");
df.roundingMode = RoundingMode.CEILING;
return df.format(value);
} else {
return "";
}
}
I don't code in Java, so please, check for any syntax misspellings. :)
I reproduced it on my Line chart using Kotlin.
Read more about ValueFormatter in the docs of MPAndroidChart, please: https://weeklycoding.com/mpandroidchart-documentation/formatting-data-values/
Upvotes: 2