diff --git a/samples/line/line-stacked-area.html b/samples/line/line-stacked-area.html index 9621c14d511..041c9a84b72 100644 --- a/samples/line/line-stacked-area.html +++ b/samples/line/line-stacked-area.html @@ -121,7 +121,7 @@ }; document.getElementById('randomizeData').addEventListener('click', function() { - $.each(config.data.datasets, function(i, dataset) { + config.data.datasets.forEach(function(dataset) { dataset.data = dataset.data.map(function() { return randomScalingFactor(); }); diff --git a/samples/scales/linear/step-size.html b/samples/scales/linear/step-size.html index d38f3e1f0bb..ced0b6c3ca3 100644 --- a/samples/scales/linear/step-size.html +++ b/samples/scales/linear/step-size.html @@ -110,6 +110,65 @@ var ctx = document.getElementById("canvas").getContext("2d"); window.myLine = new Chart(ctx, config); }; + + document.getElementById('randomizeData').addEventListener('click', function() { + config.data.datasets.forEach(function(dataset) { + dataset.data = dataset.data.map(function() { + return randomScalingFactor(); + }); + }); + + window.myLine.update(); + }); + + var colorNames = Object.keys(window.chartColors); + document.getElementById('addDataset').addEventListener('click', function() { + var colorName = colorNames[config.data.datasets.length % colorNames.length]; + var newColor = window.chartColors[colorName]; + var newDataset = { + label: 'Dataset ' + config.data.datasets.length, + backgroundColor: newColor, + borderColor: newColor, + data: [], + fill: false + }; + + for (var index = 0; index < config.data.labels.length; ++index) { + newDataset.data.push(randomScalingFactor()); + } + + config.data.datasets.push(newDataset); + window.myLine.update(); + }); + + document.getElementById('addData').addEventListener('click', function() { + if (config.data.datasets.length > 0) { + var month = MONTHS[config.data.labels.length % MONTHS.length]; + config.data.labels.push(month); + + config.data.datasets.forEach(function(dataset) { + dataset.data.push(randomScalingFactor()); + }); + + window.myLine.update(); + } + }); + + document.getElementById('removeDataset').addEventListener('click', function() { + config.data.datasets.splice(0, 1); + window.myLine.update(); + }); + + document.getElementById('removeData').addEventListener('click', function() { + config.data.labels.splice(-1, 1); // remove the label first + + config.data.datasets.forEach(function(dataset, datasetIndex) { + dataset.data.pop(); + }); + + window.myLine.update(); + }); +