I need to hide the value above bars in MPAndroidChart for barchart. I have tried all the methods available in it , but could not find the solution.
How to hide drawn values in MPAndroidChart?
24.5k views Asked by vaibhav At
2
There are 2 answers
1
On
If you want to hide values by condition, you can use a Formatter. Here is an example:
You have to call this method:
dataSet.setDrawValues(true)
and your have add a condition to your formatter:
public class MyYAxisValueFormatter implements IAxisValueFormatter {
private DecimalFormat mFormat;
public MyYAxisValueFormatter() {
// format values to 1 decimal digit
mFormat = new DecimalFormat("###,###,##0");
}
@Override
public String getFormattedValue(float value, AxisBase axis) {
String val = ""
if ((int)value > 10){
val = value
}
return mFormat.format(val);
}
/** this is only needed if numbers are returned, else return 0 */
/*@Override
public int getDecimalDigits() { return 1; }*/
}
If you want to hide all of the values you can use this:
dataSet.setDrawValues(false)
Try
dataSet.setDrawValues(false)
. This will prevent any values from being drawn.In case you want to alter (customise) the drawn values (or only individual values), you can use the ValueFormatter interface and implement your own logic (e.g. hide specific values based on a condition). Always keep in mind performance is critical when using the
ValueFormatter
.