]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Update line sample to test adding and removing datasets
authorEvert Timberg <evert.timberg@gmail.com>
Wed, 17 Jun 2015 02:05:06 +0000 (22:05 -0400)
committerEvert Timberg <evert.timberg@gmail.com>
Wed, 17 Jun 2015 02:05:06 +0000 (22:05 -0400)
samples/line.html

index b920a04ddebd0f053ccc4042842a321866644ac0..c7ea97c17e58cc4891cc6d530ccde56f83e148ca 100644 (file)
@@ -19,6 +19,8 @@
     <br>
     <br>
     <button id="randomizeData">Randomize Data</button>
+    <button id="addDataset">Add Dataset</button>
+    <button id="removeDataset">Remove Dataset</button>
     <script>
     var randomScalingFactor = function() {
         return Math.round(Math.random() * 100 * (Math.random() > 0.5 ? -1 : 1));
 
     $('#randomizeData').click(function() {
         config.data.datasets[0].data = [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()];
-
         config.data.datasets[1].data = [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()];
 
         window.myLine.update();
     });
+
+    $('#addDataset').click(function() {
+        var newDataset = {
+            label: 'Dataset ' + config.data.datasets.length,
+            borderColor: randomColor(0.4),
+            backgroundColor: randomColor(0.5),
+            pointBorderColor: randomColor(0.7),
+            pointBackgroundColor: randomColor(0.5),
+            pointBorderWidth: 1,
+            data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()]
+        };
+
+        window.myLine.addDataset(newDataset);
+    });
+
+    $('#removeDataset').click(function() {
+        window.myLine.removeDataset(0);
+    });
     </script>
 </body>