Skip to content

Commit

Permalink
Fix adding and removing datasets in bar samples (#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 a9c4e37 commit ab41173
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
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
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 ab41173

Please sign in to comment.