Make bar chart with Chart.js - Javascript Chart.js

Javascript examples for Chart.js:Bar Chart

Description

Make bar chart with Chart.js

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.min.js" type="application/javascript"></script> 
      <div style="width: 50%"> 
         <canvas id="canvas" height="450" width="600"></canvas> 
      </div> 
      <script type="text/javascript">
   var randomScalingFactor = function(){ return Math.round(Math.random()*100)};
   var barChartData = {/*  www .ja va 2  s . c  om*/
      labels : ["January","February","March","April","May","June","July"],
      datasets : [
         {
            fillColor : "rgba(220,220,220,0.5)",
            strokeColor : "rgba(220,220,220,0.8)",
            highlightFill: "rgba(220,220,220,0.75)",
            highlightStroke: "rgba(220,220,220,1)",
            data : [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()]
         },
         {
            fillColor : "rgba(151,187,205,0.5)",
            strokeColor : "rgba(151,187,205,0.8)",
            highlightFill : "rgba(151,187,205,0.75)",
            highlightStroke : "rgba(151,187,205,1)",
            data : [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()]
         }
      ]
   }
   window.onload = function(){
      var ctx = document.getElementById("canvas").getContext("2d");
      window.myBar = new Chart(ctx).Bar(barChartData, {
         responsive : true
      });
   }

      </script>  
   </body>
</html>

Related Tutorials