I am trying to create a basic bar chart but am really struggling to get the XAxis labels display properly. The XAxis labels are duplicating for some reason. Here is my cide
final String[] quarters = new String[] { "Jan", "Feb", "March", "April" };
```
IAxisValueFormatter formatter = new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
return quarters[(int) value];
}
@Override
public int getDecimalDigits() { return 0; }
};
XAxis xAxis = chart.getXAxis();
xAxis.setValueFormatter(formatter);
List<BarEntry> entries = new ArrayList<>();
entries.add(new BarEntry(0f, 30f));
entries.add(new BarEntry(1f, 80f));
entries.add(new BarEntry(2f, 60f));
entries.add(new BarEntry(3f, 50f));
BarDataSet set = new BarDataSet(entries, "BarDataSet");
BarData data = new BarData(set);
chart.setData(data);
chart.setFitBars(true);
chart.invalidate(); // refresh
```
And the chart that is created looks like this

Any idea why this is happening? I just want one label per value. Any help would be much appreciated
Same here. Moreover, I am also facing an overlapping issue. See below.

I resolved this. just added one line.
xAxis.setGranularity(1f);
setGranularity(float gran): Sets the minimum interval between the axis values. This can be used to avoid value duplicating when zooming in to a point where the number of decimals set for the axis no longer allow to distinguish between two axis values.
Cheers, that seems to do the trick!
I did the same but not working. The X axis labels are repeating.
For y axis I have disabled the zooming already.
ANy solution ?
xAxis.setGranularity(1f); saved me
thank you
I did the same but not working. The X axis labels are repeating.
For y axis I have disabled the zooming already.
ANy solution ?
Might be late, but you can try to activate the granularity before setting it at 1f. Moreover, you can set the label count following these lines :
XAxis xAxis = barChart.getXAxis();
barChart.getXAxis().setGranularityEnabled(true);
barChart.getAxisLeft().setGranularity(1f);
xAxis.setLabelCount(labelCount, false);
Most helpful comment
I resolved this. just added one line.
xAxis.setGranularity(1f);setGranularity(float gran): Sets the minimum interval between the axis values. This can be used to avoid value duplicating when zooming in to a point where the number of decimals set for the axis no longer allow to distinguish between two axis values.