Skip to content

Commit

Permalink
Fixed index out of bounds issue when using stacked bar chart
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgindi committed Jan 22, 2020
1 parent ae59e7a commit c97c8d2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ public class BarDataSet extends BarLineScatterCandleBubbleDataSet<BarEntry> impl
/**
* array of labels used to describe the different values of the stacked bars
*/
private String[] mStackLabels = new String[]{
"Stack"
};
private String[] mStackLabels = new String[]{};

public BarDataSet(List<BarEntry> yVals, String label) {
super(yVals, label);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,19 @@ public void computeLegend(ChartData<?> data) {
IBarDataSet bds = (IBarDataSet) dataSet;
String[] sLabels = bds.getStackLabels();

for (int j = 0; j < clrs.size() && j < bds.getStackSize(); j++) {
int minEntries = Math.min(clrs.size(), bds.getStackSize());

for (int j = 0; j < minEntries; j++) {
String label;
if (sLabels.length > 0) {
int labelIndex = j % minEntries;
label = labelIndex < sLabels.length ? sLabels[labelIndex] : null;
} else {
label = null;
}

computedEntries.add(new LegendEntry(
sLabels[j % sLabels.length],
label,
dataSet.getForm(),
dataSet.getFormSize(),
dataSet.getFormLineWidth(),
Expand Down

0 comments on commit c97c8d2

Please sign in to comment.