I am using MPAndroidChart library. I am using a CustomValueFormatter which formats the Float values such that their precision is 1.
CustomValueFormatter Code:
public class CustomYAxisValueFormatter implements YAxisValueFormatter {
private DecimalFormat mFormat;
public CustomYAxisValueFormatter() {
mFormat = new DecimalFormat("###,###,###,##0.0"); // sets precision to 1
}
@Override
public String getFormattedValue(float value, YAxis yAxis) {
return mFormat.format(value);
}
}
I am setting the formatter to y-axis.
Setting the formatter:
YAxis yAxis = lineChart.getAxisLeft(); //show left y-axis line
yAxis.setValueFormatter(new CustomYAxisValueFormatter()); // set value formatter to format y-values.
As a result of setValueFormatter(YAxisValueFormatter)
, the above formatter (CustomYAxisValueFormatter)
is created by default.
The problem is CustomYAxisValueFormatter can't be recreated upon zooming, thereby resulting in repetitive y-values.
Is it possible to create a CustomValueFormatter that changes precision of values based on the zoom level ?