0👍
You can create self invoking function and which will return array of datasets like this.
const options = {
type: 'line',
data: {
labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
datasets: (() => {
return [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
borderWidth: 1
}];
})()
},
options: {
scales: {
yAxes: [{
ticks: {
reverse: false
}
}]
}
}
};
var ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);
or you can create a function outside which will return datasets array and call it like below
datasets: getDataset()
- Chartjs-Best API/code library to build a timeline/chart
- Chartjs-How to show several labels and data's in the chart.js similar to npmtrend website?
Source:stackexchange.com