Skip to content

Commit

Permalink
Fix adding and removing datasets in bar samples (chartjs#5663)
Browse files Browse the repository at this point in the history
Account for zero indexing of arrays when creating a name for an added dataset and remove the last dataset in the array when removing a dataset rather than removing the first.
  • Loading branch information
TPullen21 authored and simonbrunel committed Aug 8, 2018
1 parent 6c19de9 commit 9bd905d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions samples/charts/bar/horizontal.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
var colorName = colorNames[horizontalBarChartData.datasets.length % colorNames.length];
var dsColor = window.chartColors[colorName];
var newDataset = {
label: 'Dataset ' + horizontalBarChartData.datasets.length,
label: 'Dataset ' + (horizontalBarChartData.datasets.length + 1),
backgroundColor: color(dsColor).alpha(0.5).rgbString(),
borderColor: dsColor,
data: []
Expand Down Expand Up @@ -130,7 +130,7 @@
});

document.getElementById('removeDataset').addEventListener('click', function() {
horizontalBarChartData.datasets.splice(0, 1);
horizontalBarChartData.datasets.pop();
window.myHorizontalBar.update();
});

Expand Down
4 changes: 2 additions & 2 deletions samples/charts/bar/vertical.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
var colorName = colorNames[barChartData.datasets.length % colorNames.length];
var dsColor = window.chartColors[colorName];
var newDataset = {
label: 'Dataset ' + barChartData.datasets.length,
label: 'Dataset ' + (barChartData.datasets.length + 1),
backgroundColor: color(dsColor).alpha(0.5).rgbString(),
borderColor: dsColor,
borderWidth: 1,
Expand Down Expand Up @@ -125,7 +125,7 @@
});

document.getElementById('removeDataset').addEventListener('click', function() {
barChartData.datasets.splice(0, 1);
barChartData.datasets.pop();
window.myBar.update();
});

Expand Down

0 comments on commit 9bd905d

Please sign in to comment.