Chart.js to draw bar chart horizontally - Javascript Chart.js

Javascript examples for Chart.js:Bar Chart

Description

Chart.js to draw bar chart horizontally

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>chart.js 2.1</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.1.0/Chart.bundle.min.js"></script> 
      <script type="text/javascript">
    window.onload=function(){//from w w  w .  j av  a  2 s  .  c  o  m
var config = {
    type: 'horizontalBar',
    data: {
        labels: ["Eating", "Drinking", "Sleeping", "Designing", "Coding", "Cycling", "Running"],
        datasets: [{
            label: "My First dataset",
            backgroundColor: "rgba(255,99,132,0.2)",
            borderColor: "rgba(255,99,132,1)",
            hoverBackgroundColor: "rgba(255,99,132,0.5)",
            hoverBorderColor: "rgba(255,99,132,1)",
            data: [65, -59, -90, 81, 56, 55, 40],
        }, {
            label: "My Second dataset",
            backgroundColor: "rgba(54,162,235,0.2)",
            borderColor: "rgba(54,162,235,1)",
            hoverBackgroundColor: "rgba(54,162,235,0.5)",
            hoverBorderColor: "rgba(54,162,235,1)",
            data: [28, -48, -40, 19, 96, 27, 100]
        }]
    }
};
var ctx = document.getElementById("myChart").getContext("2d");
new Chart(ctx, config);
    }

      </script> 
   </head> 
   <body> 
      <canvas id="myChart"></canvas>  
   </body>
</html>

Related Tutorials