1

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() {
        @Override
        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();
                calendar.setTimeInMillis(eu.getDailyInfo().getEpochValues()[(value_i/2)-1]);
                return (assignMonth(calendar.get(Calendar.MONTH)) + "" + String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
            } else {
                return "";
            }
        }

        @Override
        public int getDecimalDigits() {
            return 0;
        }
    });

enter image description here

enter image description here

  • 1
    You could try adding `bottomAxis.setGranularity(1f); bottomAxis.setGranularityEnabled(true);` to remove the extra labels when zooming. – TR4Android Aug 17 '16 at 21:13

1 Answers1

3

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();
bottomAxis.setGranularity(1f);
bottomAxis.setGranularityEnabled(true);

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.

Community
  • 1
  • 1
TR4Android
  • 3,200
  • 16
  • 21