14-Aug-2020: Posted an Update Below
I have a BarChart in my activity, and I am using an IndexAxisValueFormatter to display custom labels. I want labels under all of the bars that are displayed. However, the graph only shows labels under certain bars, as in the screenshot below. This problem persists even when zooming.
When the graph is displayed, the positioning of the labels is such that they are unreadable (see screenshot below), but this gets fixed after any interaction with the chart (but all labels never show).
I have tried using the XAxis.setLabelCount(entries.size(), true) with the force boolean set to true, but there was no change in the rendering. Setting a limit on the bars shown with BarChart.setVisibleXRangeMaximum(3); also does not help.
The method that displays the data is:
private void plotDataBarGraph(int[] xCoordinates, int[] yCoordinates, String label, String[] labels){
BarChart graph = findViewById(R.id.chart);
graph.setScaleYEnabled(false);
List<BarEntry> entries = new ArrayList<>();
for (int i = 0; i < xCoordinates.length; i++){
entries.add(new BarEntry(xCoordinates[i], yCoordinates[i])) ;
}
Collections.sort(entries, new EntryXComparator());
BarDataSet dataSet = new BarDataSet(entries,label);
dataSet.setColor(Color.BLUE);
dataSet.setValueTextColor(Color.BLACK);
BarData lineData = new BarData(dataSet);
graph.setData(lineData);
XAxis xAxis = graph.getXAxis();
xAxis.setLabelCount(entries.size(), true);
xAxis.setValueFormatter(new IndexAxisValueFormatter(labels));
xAxis.setLabelRotationAngle(-45);
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
graph.invalidate(); // refresh
}
This is how the chart displays when the activity is first created:
This is how the chart displays when the chart is interacted with (double tap or zoom):
I am not sure how to fix this issue, or why it is happening. Any assistance will be greatly appreciated!
Update: If I replace my BarChart with a CombinedChart, then the labels appear as expected. However, this is not suitable for what I need as I want to create a grouped bar chart (displaying two sets of data for the same month). Is there any way to achieve this using a CombinedChart? Assigning it two BarData makes it only draw the second one that was assigned.

