Show 2 types in one bar on bar chart using chartjs - Javascript Chart.js

Javascript examples for Chart.js:Bar Chart

Description

Show 2 types in one bar on bar chart using chartjs

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://rawgit.com/nnnick/Chart.js/v1.0.2/Chart.min.js"></script> 
      <script type="text/javascript" src="https://rawgit.com/Regaddi/Chart.StackedBar.js/master/src/Chart.StackedBar.js"></script> 
      <script type="text/javascript">
    window.onload=function(){/*from ww w  .  ja  va 2  s. c om*/
var randomScalingFactor = function(){ return Math.round(Math.random()*100)};
var randomColorFactor = function(){ return Math.round(Math.random()*255)};
var barChartData = {
    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()]
        },
        {
            fillColor : "rgba(240,73,73,0.5)",
            strokeColor : "rgba(240,73,73,0.8)",
            highlightFill : "rgba(240,73,73,0.75)",
            highlightStroke : "rgba(240,73,73,1)",
            data : [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()]
        }
    ]
};
var ctx = document.getElementById("canvas").getContext("2d");
var myBar = new Chart(ctx).StackedBar(barChartData);
    }

      </script> 
   </head> 
   <body> 
      <canvas id="canvas" height="300" width="600"></canvas>  
   </body>
</html>

Related Tutorials