From: Evert Timberg Date: Tue, 22 Sep 2015 01:00:58 +0000 (-0400) Subject: Update samples to no longer use old functions and instead modify the data directly X-Git-Tag: 2.0.0-alpha4~15^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F1478%2Fhead;p=thirdparty%2FChart.js.git Update samples to no longer use old functions and instead modify the data directly --- diff --git a/samples/bar.html b/samples/bar.html index 526fd8e5a..bb8c884c7 100644 --- a/samples/bar.html +++ b/samples/bar.html @@ -106,7 +106,8 @@ newDataset.data.push(randomScalingFactor()); } - window.myBar.addDataset(newDataset, 1); + barChartData.datasets.push(newDataset); + window.myBar.update(); updateLegend(); }); @@ -115,15 +116,18 @@ barChartData.labels.push('data #' + barChartData.labels.length); for (var index = 0; index < barChartData.datasets.length; ++index) { - window.myBar.addData(randomScalingFactor(), index); + //window.myBar.addData(randomScalingFactor(), index); + barChartData.datasets[index].data.push(randomScalingFactor()); } + window.myBar.update(); updateLegend(); } }); $('#removeDataset').click(function() { - window.myBar.removeDataset(0); + barChartData.datasets.splice(0, 1); + window.myBar.update(); updateLegend(); }); @@ -131,8 +135,10 @@ barChartData.labels.splice(-1, 1); // remove the label first barChartData.datasets.forEach(function(dataset, datasetIndex) { - window.myBar.removeData(datasetIndex, -1); + dataset.data.pop(); }); + + window.myBar.update(); updateLegend(); }); diff --git a/samples/combo-time-scale.html b/samples/combo-time-scale.html index 548202e2c..081683eed 100644 --- a/samples/combo-time-scale.html +++ b/samples/combo-time-scale.html @@ -145,7 +145,8 @@ newDataset.data.push(randomScalingFactor()); } - window.myLine.addDataset(newDataset); + config.data.datasets.push(newDataset); + window.myLine.update(); updateLegend(); }); @@ -157,15 +158,17 @@ ); for (var index = 0; index < config.data.datasets.length; ++index) { - window.myLine.addData(randomScalingFactor(), index); + config.data.datasets[index].data.push(randomScalingFactor()); } + window.myLine.update(); updateLegend(); } }); $('#removeDataset').click(function() { - window.myLine.removeDataset(0); + config.data.datasets.splice(0, 1); + window.myLine.update(); updateLegend(); }); @@ -173,9 +176,10 @@ config.data.labels.splice(-1, 1); // remove the label first config.data.datasets.forEach(function(dataset, datasetIndex) { - window.myLine.removeData(datasetIndex, -1); + config.data.datasets[datasetIndex].data.pop(); }); + window.myLine.update(); updateLegend(); }); diff --git a/samples/doughnut.html b/samples/doughnut.html index ae6bbc9e5..728c8847a 100644 --- a/samples/doughnut.html +++ b/samples/doughnut.html @@ -144,7 +144,8 @@ newDataset.backgroundColor.push(randomColor(0.7)); } - window.myDoughnut.addDataset(newDataset); + config.data.datasets.push(newDataset); + window.myDoughnut.update(); updateLegend(); }); @@ -153,15 +154,18 @@ config.data.labels.push('data #' + config.data.labels.length); $.each(config.data.datasets, function(index, dataset) { - window.myDoughnut.addData(randomScalingFactor(), index, dataset.data.length, randomColor(0.7)); + dataset.data.push(randomScalingFactor()); + dataset.backgroundColor.push(randomColor(0.7)); }); + window.myDoughnut.update(); updateLegend(); } }); $('#removeDataset').click(function() { - window.myDoughnut.removeDataset(0); + config.data.datasets.splice(0, 1); + window.myDoughnut.update(); updateLegend(); }); @@ -169,9 +173,11 @@ config.data.labels.splice(-1, 1); // remove the label first config.data.datasets.forEach(function(dataset, datasetIndex) { - window.myDoughnut.removeData(datasetIndex, -1); + dataset.data.pop(); + dataset.backgroundColor.pop(); }); + window.myDoughnut.update(); updateLegend(); }); diff --git a/samples/line-logarithmic.html b/samples/line-logarithmic.html index 21159e6ee..613499010 100644 --- a/samples/line-logarithmic.html +++ b/samples/line-logarithmic.html @@ -126,7 +126,8 @@ newDataset.data.push(randomScalingFactor()); } - window.myLine.addDataset(newDataset); + config.data.datasets.push(newDataset); + window.myLine.update(); updateLegend(); }); @@ -135,15 +136,17 @@ config.data.labels.push('dataset #' + config.data.labels.length); for (var index = 0; index < config.data.datasets.length; ++index) { - window.myLine.addData(randomScalingFactor(), index); + config.data.datasets[index].data.push(randomScalingFactor()); } + window.myLine.update(); updateLegend(); } }); $('#removeDataset').click(function() { - window.myLine.removeDataset(0); + config.data.datasets.splice(0, 1); + window.myLine.update(); updateLegend(); }); @@ -151,9 +154,10 @@ config.data.labels.splice(-1, 1); // remove the label first config.data.datasets.forEach(function(dataset, datasetIndex) { - window.myLine.removeData(datasetIndex, -1); + dataset.data.pop(); }); + window.myLine.update(); updateLegend(); }); diff --git a/samples/line-scale-override.html b/samples/line-scale-override.html index 6603b5c04..a92b14a1b 100644 --- a/samples/line-scale-override.html +++ b/samples/line-scale-override.html @@ -101,7 +101,8 @@ newDataset.data.push(randomScalingFactor()); } - window.myLine.addDataset(newDataset); + config.data.datasets.push(newDataset); + window.myLine.update(); }); $('#addData').click(function() { @@ -109,21 +110,26 @@ config.data.labels.push('dataset #' + config.data.labels.length); for (var index = 0; index < config.data.datasets.length; ++index) { - window.myLine.addData(randomScalingFactor(), index); + config.data.datasets[index].data.push(randomScalingFactor()); } + + window.myLine.update(); } }); $('#removeDataset').click(function() { - window.myLine.removeDataset(0); + config.data.datasets.splice(0, 1); + window.myLine.update(); }); $('#removeData').click(function() { config.data.labels.splice(-1, 1); // remove the label first config.data.datasets.forEach(function(dataset, datasetIndex) { - window.myLine.removeData(datasetIndex, -1); + dataset.data.pop(); }); + + window.myLine.update(); }); diff --git a/samples/line-time-scale.html b/samples/line-time-scale.html index 3fc97b52b..124c9d9c7 100644 --- a/samples/line-time-scale.html +++ b/samples/line-time-scale.html @@ -144,7 +144,8 @@ newDataset.data.push(randomScalingFactor()); } - window.myLine.addDataset(newDataset); + config.data.datasets.push(newDataset); + window.myLine.update(); updateLegend(); }); @@ -158,15 +159,17 @@ ); for (var index = 0; index < config.data.datasets.length; ++index) { - window.myLine.addData(randomScalingFactor(), index); + config.data.datasets[index].data.push(randomScalingFactor()); } + window.myLine.update(); updateLegend(); } }); $('#removeDataset').click(function() { - window.myLine.removeDataset(0); + config.data.datasets.splice(0, 1); + window.myLine.update(); updateLegend(); }); @@ -174,9 +177,10 @@ config.data.labels.splice(-1, 1); // remove the label first config.data.datasets.forEach(function(dataset, datasetIndex) { - window.myLine.removeData(datasetIndex, -1); + dataset.data.pop(); }); + window.myLine.update(); updateLegend(); }); diff --git a/samples/line-x-axis-filter.html b/samples/line-x-axis-filter.html index 71a1b8844..05d18d73d 100644 --- a/samples/line-x-axis-filter.html +++ b/samples/line-x-axis-filter.html @@ -108,7 +108,8 @@ newDataset.data.push(randomScalingFactor()); } - window.myLine.addDataset(newDataset); + config.data.datasets.push(newDataset); + window.myLine.update(); }); $('#addData').click(function() { @@ -116,21 +117,26 @@ config.data.labels.push('dataset #' + config.data.labels.length); for (var index = 0; index < config.data.datasets.length; ++index) { - window.myLine.addData(randomScalingFactor(), index); + config.data.datasets[index].data.push(randomScalingFactor()); } + + window.myLine.update(); } }); $('#removeDataset').click(function() { - window.myLine.removeDataset(0); + config.data.datasets.splice(0, 1); + window.myLine.update(); }); $('#removeData').click(function() { config.data.labels.splice(-1, 1); // remove the label first config.data.datasets.forEach(function(dataset, datasetIndex) { - window.myLine.removeData(datasetIndex, -1); + dataset.data.pop(); }); + + window.myLine.update(); }); diff --git a/samples/line.html b/samples/line.html index 192702888..6d6816e51 100644 --- a/samples/line.html +++ b/samples/line.html @@ -125,7 +125,8 @@ newDataset.data.push(randomScalingFactor()); } - window.myLine.addDataset(newDataset); + config.data.datasets.push(newDataset); + window.myLine.update(); updateLegend(); }); @@ -133,16 +134,18 @@ if (config.data.datasets.length > 0) { config.data.labels.push('dataset #' + config.data.labels.length); - for (var index = 0; index < config.data.datasets.length; ++index) { - window.myLine.addData(randomScalingFactor(), index); - } + $.each(config.data.datasets, function(i, dataset) { + dataset.data.push(randomScalingFactor()); + }); + window.myLine.update(); updateLegend(); } }); $('#removeDataset').click(function() { - window.myLine.removeDataset(0); + config.data.datasets.splice(0, 1); + window.myLine.update(); updateLegend(); }); @@ -150,9 +153,10 @@ config.data.labels.splice(-1, 1); // remove the label first config.data.datasets.forEach(function(dataset, datasetIndex) { - window.myLine.removeData(datasetIndex, -1); + dataset.data.pop(); }); + window.myLine.update(); updateLegend(); }); diff --git a/samples/pie.html b/samples/pie.html index 571efb037..3d05fc20c 100644 --- a/samples/pie.html +++ b/samples/pie.html @@ -108,11 +108,13 @@ data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()] }; - window.myPie.addDataset(newDataset); + config.data.datasets.push(newDataset); + window.myPie.update(); }); $('#removeDataset').click(function() { - window.myPie.removeDataset(0); + config.data.datasets.splice(0, 1); + window.myPie.update(); }); diff --git a/samples/polar-area.html b/samples/polar-area.html index 89915530b..678aac69c 100644 --- a/samples/polar-area.html +++ b/samples/polar-area.html @@ -93,23 +93,25 @@ if (config.data.datasets.length > 0) { config.data.labels.push('dataset #' + config.data.labels.length); - for (var index = 0; index < config.data.datasets.length; ++index) { - config.data.datasets[index].backgroundColor.push(randomColor()); - window.myPolarArea.addData(randomScalingFactor(), index); - } + $.each(config.data.datasets, function(i, dataset) { + dataset.backgroundColor.push(randomColor()); + dataset.data.push(randomScalingFactor()); + }); + window.myPolarArea.update(); updateLegend(); } }); $('#removeData').click(function() { - config.data.labels.splice(-1, 1); // remove the label first + config.data.labels.pop(); // remove the label first - config.data.datasets.forEach(function(dataset, datasetIndex) { - dataset.backgroundColor.splice(-1, 1); - window.myPolarArea.removeData(datasetIndex, -1); + $.each(config.data.datasets, function(i, dataset) { + dataset.backgroundColor.pop(); + dataset.data.pop(); }); + window.myPolarArea.update(); updateLegend(); }); diff --git a/samples/radar.html b/samples/radar.html index 80b544e0d..c9b559aef 100644 --- a/samples/radar.html +++ b/samples/radar.html @@ -16,7 +16,7 @@ - ]
+

Legend

@@ -97,7 +97,8 @@ newDataset.data.push(randomScalingFactor()); } - window.myRadar.addDataset(newDataset); + config.data.datasets.push(newDataset); + window.myRadar.update(); updateLegend(); }); @@ -105,26 +106,29 @@ if (config.data.datasets.length > 0) { config.data.labels.push('dataset #' + config.data.labels.length); - for (var index = 0; index < config.data.datasets.length; ++index) { - window.myRadar.addData(randomScalingFactor(), index); - } + $.each(config.data.datasets, function (i, dataset) { + dataset.data.push(randomScalingFactor()); + }); + window.myRadar.update(); updateLegend(); } }); $('#removeDataset').click(function() { - window.myRadar.removeDataset(0); + config.data.datasets.splice(0, 1); + window.myRadar.update(); updateLegend(); }); $('#removeData').click(function() { - config.data.labels.splice(-1, 1); // remove the label first + config.data.labels.pop(); // remove the label first - config.data.datasets.forEach(function(dataset, datasetIndex) { - window.myRadar.removeData(datasetIndex, -1); + $.each(config.data.datasets, function(i, dataset) { + dataset.data.pop(); }); + window.myRadar.update(); updateLegend(); });