]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Update line sample to change the entire data object 1646/head
authorEvert Timberg <evert.timberg@gmail.com>
Fri, 13 Nov 2015 15:01:38 +0000 (10:01 -0500)
committerEvert Timberg <evert.timberg@gmail.com>
Fri, 13 Nov 2015 15:01:38 +0000 (10:01 -0500)
samples/line.html

index 45cd9229ca9979bf2f1f700e9fc065d225d86878..0647173b440eac559f98c48e7e3998f872e9df3a 100644 (file)
@@ -19,6 +19,7 @@
     <br>
     <br>
     <button id="randomizeData">Randomize Data</button>
+    <button id="changeDataObject">Change Data Object</button>
     <button id="addDataset">Add Dataset</button>
     <button id="removeDataset">Remove Dataset</button>
     <button id="addData">Add Data</button>
             updateLegend();
         });
 
+        $('#changeDataObject').click(function() {
+            config.data = {
+                labels: ["July", "August", "September", "October", "November", "December"],
+                datasets: [{
+                    label: "My First dataset",
+                    data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()],
+                    fill: false,
+                }, {
+                    label: "My Second dataset",
+                    fill: false,
+                    data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()],
+                }]
+            };
+
+            $.each(config.data.datasets, function(i, dataset) {
+                dataset.borderColor = randomColor(0.4);
+                dataset.backgroundColor = randomColor(0.5);
+                dataset.pointBorderColor = randomColor(0.7);
+                dataset.pointBackgroundColor = randomColor(0.5);
+                dataset.pointBorderWidth = 1;
+            });
+
+            // Update the chart
+            window.myLine.update();
+        });
+
         $('#addDataset').click(function() {
             var newDataset = {
                 label: 'Dataset ' + config.data.datasets.length,