Create a horizontal stacked bar chart with Chart.JS - Javascript Chart.js

Javascript examples for Chart.js:Bar Chart

Description

Create a horizontal stacked 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"> 
      <script type="text/javascript">
    window.onload=function(){//from   w  w w. j  av a2 s .c o m
var config = {
      type: 'horizontalBar',
      data: {
        labels: ["A", "B", "C", "D", "E"],
        datasets: [{
          label: "Dataset 1",
          backgroundColor: "rgba(154,178,96,0.5)",
          hoverBackgroundColor: "rgba(154,178,96,1)",
          data: [10, 15, 5, 81, 55],
        }, {
          label: "Dataset 2",
          backgroundColor: "rgba(197,213,167,0.5)",
          hoverBackgroundColor: "rgba(197,213,167,1)",
          data: [90, 85, 95, 19, 45]
        }]
      },
      options: {
        scales: {
          xAxes: [{
            stacked: true
          }],
          yAxes: [{
            stacked: true
          }]
        }
      }
    };
    var ctx = document.getElementById("myChart").getContext("2d");
    new Chart(ctx, config);
    }

      </script> 
   </head> 
   <body> 
      <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.2.2/Chart.min.js"></script> 
      <canvas id="myChart"></canvas>  
   </body>
</html>

Related Tutorials