0
votes

The bars in my barchart are not aligned with the labels - see : https://imgur.com/gallery/QVtIvXq

My X Axis:

 XAxis xAxis = chart.getXAxis();
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setLabelCount(values.length + 1, true);
    xAxis.setDrawLabels(true);
    xAxis.setCenterAxisLabels(true);
    xAxis.setValueFormatter(new MyXAxisValueFormatter(values));
    xAxis.setGranularity(10f);
    xAxis.setGranularityEnabled(true);
    xAxis.setDrawGridLines(true);
    xAxis.setDrawAxisLine(false);
    //xAxis.setAxisMinimum(0);
    xAxis.setAxisMaximum(values.length+1);


  // custom X-axis labels
     String[] values = new String[]{"Excited", "Happy", "Confident", "Proud", "Content", "Fine",
    "Relaxed", "Calm", "Tired", "Guilty", "Sad", "Depressed", "Embarrassed", "Upset", "Stressed",
     "Anxious", "Confused", "Disgusted"};

Any help would be greatly appreciated

1

1 Answers

0
votes

What worked for me was to remove the line xAxis.setAxisMaximum(values.length+1); and instead insert a blank data set. This ensures all the labels are displayed without enforcing a maximum which was causing the bars not to align properly for some reason. Hope this helps someone in the future.