'How to draw x-axis labels between 2 Bars from 1 group of BarChart Android Studio
I'm using BarCharts for a project in Android Studio I created a Barchart with 2 vertical bars for each group. I also changed the x axis by adding a list of names (Strings), but it doesn't look well. I want the x axis to always be between the 2 vertical bars from 1 group (because those 2 bars are correspondent for 1 name from the x axis). Is this possible? I need the x axis to always be between the blue bar and the yellow bar. To have 1 x axis label for 1 bar group. Here is how my chart looks right now: My chart at the moment
Here is my code:
ArrayList<BarEntry> entries = new ArrayList<>();
ArrayList<BarEntry> firstEntries = new ArrayList<>();
for(int i=0;i<scorelist.size();i++)
{
BarEntry barEntry = new BarEntry(i, scorelist.get(i));
entries.add(barEntry);
}
for(int i=0;i<first3Scorelist.size();i++)
{
BarEntry barEntry = new BarEntry(i, first3Scorelist.get(i));
firstEntries.add(barEntry);
}
BarDataSet barDataSet2 = new BarDataSet(entries, "Last Games Score");
barDataSet2.setColors(Color.YELLOW);
BarDataSet barDataSet1 = new BarDataSet(firstEntries, "First Games Score");
barDataSet1.setColors(Color.CYAN);
BarData barData = new BarData(barDataSet1,barDataSet2);
barChart.setData(barData);
barChart.getXAxis().setValueFormatter(new IndexAxisValueFormatter(nameList));
barChart.getXAxis().setTextColor(Color.MAGENTA);
barChart.getXAxis().setTextSize(10);
barChart.setVisibleXRangeMaximum(7);
barData.setBarWidth(0.3f);
float barSpace = 0.01f;
float groupSpace = 0.3f;
barChart.animateY(3000);
barChart.animate();
barChart.groupBars((float) -0.2, groupSpace, barSpace);
barChart.getDescription().setEnabled(false);
barChart.invalidate();
}
Thank you so much!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|