James James - 9 months ago 71
Android Question

MpAndroidChart zoom String value error

I am using MpAndroidChart and it is going very well except for one problem. When I zoom in on a specific region of the graph, the X values appear multiple times in a clumped manner. I override the

X axis setValueFormatter
(code below along with some pictures) to display dates returned from inputted data. Has anyone had this happen to them, and if so, do you know the cause of it? I am considering just disabling the zoomable option, but I would prefer to have it. Thank You!

bottomAxis.setValueFormatter(new AxisValueFormatter() {
public String getFormattedValue(float value, AxisBase axis) {
// return values will all be the values of the dates array
int value_i = (int) value;
if (value_i % 2 == 0 && (value_i / 2) <= epochs.length && value_i >= 2) {
Calendar calendar = Calendar.getInstance();
return (assignMonth(calendar.get(Calendar.MONTH)) + "" + String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
} else {
return "";

public int getDecimalDigits() {
return 0;

enter image description here

enter image description here


If you want to remove the extra labels you can use the granularity feature. For example, if your bar chart is index-based, the following should work:

bottomAxis = mBarChart.getXAxis();

Note: this is especially helpful for removing the duplicated labels when using a LabelFormatter or similiar in the new version 3.0.0 of this library.

Also, see this answer for more information on the granularity feature.