Ktoto210978,
как вариант ...
let cards = [...document.querySelectorAll('.card > canvas')];
cards = cards.map(elem => {
let cfd = {
type: 'line',
data: {
labels: [],
datasets: [{
data: [],
borderColor: 'green',
borderWidth: 2,
tension: 0.5
}]
},
options: {
plugins: {
legend: {
display: false
}
},
indexAxis: 'x',
responsive: true,
suggestedMin: -10,
suggestedMax: 200,
scales: {
Y: {
beginAtZero: true
}
}
}
};
return new Chart(elem, cfd);
})
function addData(chart, label, data, color) {
chart.data.labels = label;
chart.data.datasets[0].data = data;
chart.data.datasets[0].borderColor = color;
chart.update();
}
let opt = [
[dynamic.su, 'blue'],
[dynamic.us, 'green'],
[dynamic.pr, 'red'],
[dynamic.sp, 'orange']
];
cards.forEach((elem, i) => addData(elem, dynamic.days, ...opt[i]));