Add color support for charts

This commit is contained in:
Jordan Wages 2025-07-18 23:03:04 -05:00
commit 44ee039ca6
3 changed files with 41 additions and 17 deletions

View file

@ -53,18 +53,27 @@
options.scales.x = { stacked: true };
options.scales.y.stacked = true;
}
const dataset = {
label: rep.label,
data: values,
borderWidth: 1,
fill: rep.chart !== 'bar' && rep.chart !== 'stackedBar'
};
if (rep.colors) {
dataset.backgroundColor = rep.colors;
dataset.borderColor = rep.colors;
} else if (rep.color) {
dataset.backgroundColor = rep.color;
dataset.borderColor = rep.color;
} else {
dataset.backgroundColor = 'rgba(54, 162, 235, 0.5)';
dataset.borderColor = 'rgba(54, 162, 235, 1)';
}
new Chart(document.getElementById('chart-' + rep.name), {
type: chartType,
data: {
labels: labels,
datasets: [{
label: rep.label,
data: values,
backgroundColor: 'rgba(54, 162, 235, 0.5)',
borderColor: 'rgba(54, 162, 235, 1)',
borderWidth: 1,
fill: rep.chart !== 'bar' && rep.chart !== 'stackedBar',
}]
datasets: [dataset]
},
options: options
});