1 回答
TA贡献2003条经验 获得超2个赞
您可以只设置为与条形图数据具有相同长度的颜色数组。backgroundColor
例如:
const config = {
type: 'bar',
data: {
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
datasets: [
{
label: 'Dataset 1',
backgroundColor: ['red', 'red', 'blue', 'blue', 'blue', 'red', 'red'],
borderWidth: 1,
data: [-3, 30, -10, 33, -9, 14, -11],
}
],
},
options: {
legend: {
display: false
}
}
};
const ctx = document.getElementById('canvas').getContext('2d');
new Chart(ctx, config);
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.js"></script>
<body>
<canvas id="canvas" width="600" height="400"></canvas>
</body>
添加回答
举报