stacking bar chart and line chart - Javascript Chart.js

Javascript examples for Chart.js:Bar Chart

Description

stacking bar chart and line chart

Demo Code

ResultView the demo in separate window

<html lang="en">
   <head> 
      <title>Stacked Bar Chart with Unstacked Lines Combo on Same Scale</title> 
   </head> 
   <body translate="no"> 
      <div style="width: 75%"> 
         <canvas id="canvas"></canvas> 
      </div> 
      <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
      <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script> 
      <script>
      window.chartColors = {/*from   ww w  .ja v  a 2  s  .  c  om*/
  red: 'rgb(255, 99, 132)',
  orange: 'rgb(255, 159, 64)',
  yellow: 'rgb(255, 205, 86)',
  green: 'rgb(75, 192, 192)',
  blue: 'rgb(54, 162, 235)',
  purple: 'rgb(153, 102, 255)',
  grey: 'rgb(231,233,237)'
};
var ctx = document.getElementById("canvas").getContext("2d");
var myChart = new Chart(ctx, {
  type: 'bar',
  data: {
    labels: ["January", "February", "March", "April", "May", "June", "July"],
    datasets: [{
      type: 'line',
      label: 'Dataset 1',
      borderColor: window.chartColors.green,
      borderWidth: 2,
      fill: false,
      data: [5, 3, 4, 10, 8, 9, 2]
    }, {
      type: 'line',
      label: 'Dataset 2',
      borderColor: window.chartColors.orange,
      borderWidth: 2,
      fill: false,
      data: [8, 5, 2, 8, 7, 2, 6]
    }, {
      type: 'bar',
      label: 'Dataset 3',
      backgroundColor: window.chartColors.red,
      stack: 'Stack 0',
      data: [2, 4, 1, 3, 7, 3, 6],
      borderColor: 'white',
      borderWidth: 2
    }, {
      type: 'bar',
      label: 'Dataset 4',
      backgroundColor: window.chartColors.blue,
      stack: 'Stack 0',
      data: [7, 2, 4, 5, 6, 4, 2]
    }]
  },
  options: {
    responsive: true,
    title: {
      display: true,
      text: 'Chart.js Stacked Bar and Unstacked Line Combo Chart'
    },
    tooltips: {
      mode: 'index',
      intersect: true
    },
    scales: {
      xAxes: [{
        stacked: true,
      }]
    }
  }
});
      //# sourceURL=pen.js
    
      </script>  
   </body>
</html>

Related Tutorials