4👍
✅
You can use an immediately invoked function like below:
datasets:
(function (main_arr) {
var out = [];
for(var i=0; i<main_arr.length; i++) {
out.push({
label: 'Group ' + i + ': ' + main_arr[i].length,
data: main_arr[i],
backgroundColor: 'lightblue'
});
}
return out;
})(main_arr)
},
The function creates the datasets array and returns it to datasets
property of chart options object.
Here is a fiddle: https://jsfiddle.net/beaver71/4nf41tq9/
Source:stackexchange.com