Ktoto210978,
let chartDynamicUs, chartDynamicPr, chartDynamicSp, chartDynamicSu;
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 arrCfg = Array.from({
length: 4
}, _ => ({
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
}
}
}
}));
chartDynamicUs = new Chart($('#chartDynamicUs'), arrCfg[0]);
chartDynamicPr = new Chart($('#chartDynamicPr'), arrCfg[1]);
chartDynamicSp = new Chart($('#chartDynamicSp'), arrCfg[2]);
chartDynamicSu = new Chart($('#chartDynamicSu'), arrCfg[3]);
addData(chartDynamicSu, dynamic.days, dynamic.su, 'blue');
addData(chartDynamicUs, dynamic.days, dynamic.us, 'green');
addData(chartDynamicPr, dynamic.days, dynamic.pr, 'red');
addData(chartDynamicSp, dynamic.days, dynamic.sp, 'orange');