]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Update pie sample file to support add and remove datasets
authorEvert Timberg <evert.timberg@gmail.com>
Wed, 17 Jun 2015 02:16:28 +0000 (22:16 -0400)
committerEvert Timberg <evert.timberg@gmail.com>
Wed, 17 Jun 2015 02:16:28 +0000 (22:16 -0400)
samples/pie.html

index 6f97bd43eec453e7d376c7933ab2de7b4d4ea574..2ae05735551c538f4dd059f8c10e33a3d35eb6b1 100644 (file)
@@ -8,16 +8,18 @@
 </head>
 
 <body>
-    <div id="canvas-holder">
+    <div id="canvas-holder" style="width:50%">
         <canvas id="chart-area" width="300" height="300" />
     </div>
     <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);
     };
-    var randomColorFactor = function() {
-        return Math.round(Math.random() * 255);
+    var randomColor = function(opacity) {
+        return 'rgba(' + Math.round(Math.random() * 255) + ',' + Math.round(Math.random() * 255) + ',' + Math.round(Math.random() * 255) + ',' + (opacity || '.3') + ')';
     };
 
     var config = {
         });
         window.myPie.update();
     });
+
+    $('#addDataset').click(function() {
+        var newDataset = {
+            backgroundColor: [randomColor(0.7), randomColor(0.7), randomColor(0.7), randomColor(0.7), randomColor(0.7)],
+            data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()]
+        };
+
+        window.myPie.addDataset(newDataset);
+    });
+
+    $('#removeDataset').click(function() {
+        window.myPie.removeDataset(0);
+    });
     </script>
 </body>