I want to make a bar chart with 3 different datasets grouped together at each data point like so:
However, I am unable to group the bars together using the library's provided groupBars
method because no matter what x-value I set for an entry, it groups the bars according to the interval I specify in its parameters.
For example, if I generate a dataset with entry x-values {0, 5, 13, 17...50} and call `groupBars', all of my entries are gathered 1 x-value apart like so:
What I want is the bars to each be grouped and each be visible at their specified x-value. If I simply remove the groupBars
call, I get something similar to what I want but not quite since the bars are all overlapping, like so:
How do I achieve a result similar to the above image but with the bar of each dataset completely visible? Here is my code for generating the dataset and grouping the bars:
ArrayList<BarEntry> happinessValues = new ArrayList<>();
ArrayList<BarEntry> stressValues = new ArrayList<>();
ArrayList<BarEntry> painValues = new ArrayList<>();
for (int i = 0; i < 50; ++i) {
happinessValues.add(new BarEntry(
i,
datapoint.getHappiness()));
stressValues.add(new BarEntry(
i,
datapoint.getStress()));
painValues.add(new BarEntry(
i,
datapoint.getPain()));
}
HappinessDataset happyDataset;
BarDataSet stressDataset, painDataset;
happyDataset = new HappinessDataset(happinessValues, "Happiness");
stressDataset = new BarDataSet(stressValues, "Stress");
painDataset = new BarDataSet(painValues, "Pain");
BarData data = new BarData(happyDataset, stressDataset, painDataset);
mChart.setData(data);
mChart.getXAxis().setAxisMinimum(0);
mChart.getXAxis().setAxisMaximum(50);
float groupSpace = 0.4f;
float barSpace = 0f; // x3 DataSet
float barWidth = 0.2f; // x3 DataSet
// (0.2 + 0) * 3 + 0.4 = 1.00 -> interval per "group"
mChart.groupBars(startTime, groupSpace, barSpace);