Chartjs-Bar chart is not grouped properly in chartjs

1👍

You should pass the data in the below way to get the desired output. All the items which need to be showed in x-axis should be passed in the labels array, then each dataset i.e. “Pearson” and “srinath” should be passed as a separate dataset with data as corresponding values for the x-axis. Fiddle -> http://jsfiddle.net/Lzo5g01n/25/

var ctx = document.getElementById("myChart").getContext('2d');
var myChart = new Chart(ctx, {
    type: 'bar',
    data: {
        labels: ["CPI", "Cutting", "Ironing", "Mending"],
        datasets: [{
            label: 'Pearson',
            data: [1, 1, 0, 1],
            backgroundColor: 'rgba(255, 99, 132, 0.2)',              
            borderColor: 'rgba(255,99,132,1)',
            borderWidth: 1
        },{
            label: 'srinath',
            data: [1, 0, 1, 0],
            backgroundColor: 'rgba(54, 162, 235, 0.2)',              
            borderColor: 'rgba(54, 162, 235, 1)',
            borderWidth: 1
        }
    ]},
    options: {
        scales: {
            yAxes: [{
                ticks: {
                    beginAtZero:true
                }
            }]
        }
    }
});

Leave a comment