]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
improve progress-bar sample
authorVille Hämäläinen <hamalainen.ville.p@gmail.com>
Sun, 28 Feb 2016 07:29:29 +0000 (09:29 +0200)
committerVille Hämäläinen <hamalainen.ville.p@gmail.com>
Sun, 28 Feb 2016 07:29:29 +0000 (09:29 +0200)
- set title
- set same size canvas as other samples
- fix x-axis labels when adding data
- remove user select from canvas

samples/AnimationCallbacks/progress-bar.html

index 142f8b1a2f979e8647a57e23f21e44ac79553ce3..7d79d6c1d8c4884e47bcd7aa9edd5ef3753237f5 100644 (file)
@@ -5,15 +5,17 @@
     <script src="../../dist/Chart.bundle.js"></script>
     <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
     <style>
-        canvas {
-            -webkit-box-shadow: 0 0 20px 0 rgba(0, 0, 0, .5);
-        }
+    canvas {
+        -moz-user-select: none;
+        -webkit-user-select: none;
+        -ms-user-select: none;
+    }
     </style>
 </head>
 
 <body>
-    <div style="width: 100 %;">
-        <canvas id="canvas" style="width: 100 % ;height: 100 %"></canvas>
+    <div style="width: 75%;">
+        <canvas id="canvas"></canvas>
         <progress id="animationProgress" max="1" value="0" style="width: 100%"></progress>
     </div>
     <br>
@@ -24,6 +26,8 @@
     <button id="addData">Add Data</button>
     <button id="removeData">Remove Data</button>
     <script>
+        var MONTHS = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
+
         var randomScalingFactor = function() {
             return Math.round(Math.random() * 100);
         };
                 }]
             },
             options: {
+                title:{
+                    display:true,
+                    text:"Chart.js Line Chart - Animation Progress Bar"
+                },
                 animation: {
                     duration: 2000,
                     onProgress: function(animation) {
 
         $('#addData').click(function() {
             if (config.data.datasets.length > 0) {
-                config.data.labels.push('dataset #' + config.data.labels.length);
+                var month = MONTHS[config.data.labels.length % MONTHS.length];
+                config.data.labels.push(month);
 
                 $.each(config.data.datasets, function(i, dataset) {
                     dataset.data.push(randomScalingFactor());