Add color support for charts
This commit is contained in:
parent
f0653f972f
commit
44ee039ca6
3 changed files with 41 additions and 17 deletions
|
@ -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
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue