Fix adding and removing datasets in bar samples (#5663)

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.
This commit is contained in:
Tom Pullen
2018-08-08 17:52:56 +01:00
committed by Simon Brunel
parent a9c4e377a7
commit ab41173d9b
2 changed files with 4 additions and 4 deletions

View File

@@ -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: []
@@ -130,7 +130,7 @@
});
document.getElementById('removeDataset').addEventListener('click', function() {
horizontalBarChartData.datasets.splice(0, 1);
horizontalBarChartData.datasets.pop();
window.myHorizontalBar.update();
});

View File

@@ -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,
@@ -125,7 +125,7 @@
});
document.getElementById('removeDataset').addEventListener('click', function() {
barChartData.datasets.splice(0, 1);
barChartData.datasets.pop();
window.myBar.update();
});