Chartjs-How to create datasets for all labels for stacked bar in chart.js?

0👍

The colors of my dataset were inside brackets, that was causing it to be taken as an array, I left only the value.

I hope this helps someone else.

              
var ctx = document.getElementById("myChart")

var myChart = new Chart(ctx, {
	type: "bar",
  data: {
  labels: ['Product 1','Product 2','Product 3','Product 4','Product 5','Product 6'],
    datasets: [{
      label: 'Count 1',
      data: [10,2,2,2,0,1],
      backgroundColor: 
        'rgba(255, 99, 132, 0.2)'
    }, {
      label: 'Count 2',
      data: [10,5,1,0,5,4],
      backgroundColor: 
        'rgba(54, 162, 235, 0.2)'
    }]
  },
  options: {
    scales: {
      xAxes: [{
        stacked: true
      }],
      yAxes: [{
        stacked: true,
      }]
    }
  }
});
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.3/Chart.min.js"></script>
</head>

<canvas id="myChart"></canvas>

Attached link in JsFiddle

https://jsfiddle.net/espinoza/uzjyrfv2/1/

Leave a comment