Chartjs-ChartJS – How to provide datasets an array of objects

0👍

try:

   new Chart(canvas, {
    type: 'bar',
    data: {
        labels: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'],

        // chartData.datasets is an array
        datasets: chartData.datasets,

    },

0👍

Juan’s answer will do what you want. If, for some reason, you only want 0 to 23, you can pass chartData.datasets.slice(0, 24) instead of chartData.datasets.

EDIT

let data = [];
chartData.datasets.forEach(a => data = data.concat(a));

And pass data instead.

This will concatenate every entry in chartData.datasets

Leave a comment