SolvedMPAndroidChart how to display dynamic labels for XAxis

I am using bar chart and i am unable to display dynamic xaxis labels on the chart, so far i have been able to show only one label for all bars using value formatter, please can anyone show me how to do it. It is a good library but still not sufficient documentation for noobs. currently i am using this code:

XAxis xval = barChart.getXAxis();
        xval.setDrawLabels(true);
        xval.setValueFormatter(new AxisValueFormatter() {
            @Override
            public String getFormattedValue(float value, AxisBase axis) {
                return  "Label";
            }

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

    xval.setPosition(XAxis.XAxisPosition.BOTTOM);
    xval.setDrawGridLines(false);
35 Answers

✔️Accepted Answer

There's also an IndexAxisValueFormatter class if you have a simple lookup.

// Look-up table
final String[] weekdays = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};

// Set the value formatter
XAxis xAxis = chart.getXAxis();
xAxis.setValueFormatter(new IndexAxisValueFormatter(weekdays));

Other Answers:

@muzammil22 i had the same problem , here is how i solved it. waterRecs is the Arraylist with the X values i want

   XAxis xAxis = barchart.getXAxis();
   xAxis.setValueFormatter(new IAxisValueFormatter()
    {

        @Override
        public String getFormattedValue(float value, AxisBase axis)
        {
            System.out.println(value);
            if(((int)value)<waterRecs.size())
            {
                return  (waterRecs.get((int)value).getDate());
            }
            else
            {
                return "";
            }
        }


    });

More Issues: