From ab41173d9b2abb9c543c82c360abb51c3efcd778 Mon Sep 17 00:00:00 2001 From: Tom Pullen Date: Wed, 8 Aug 2018 17:52:56 +0100 Subject: [PATCH] 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. --- samples/charts/bar/horizontal.html | 4 ++-- samples/charts/bar/vertical.html | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/samples/charts/bar/horizontal.html b/samples/charts/bar/horizontal.html index 6450e014d92..e174ad2ca35 100644 --- a/samples/charts/bar/horizontal.html +++ b/samples/charts/bar/horizontal.html @@ -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(); }); diff --git a/samples/charts/bar/vertical.html b/samples/charts/bar/vertical.html index e9348b274fd..5127d4937c2 100644 --- a/samples/charts/bar/vertical.html +++ b/samples/charts/bar/vertical.html @@ -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(); });