Ian*_*ako 2 javascript chart.js
我正在使用Chart.js。我有一条具有特定颜色的数据线。我希望这些数据线的点具有不同的颜色。根据文档,您可以使用Chart.defaults.global.elements.point.backgroundColor
var ctxLine = document.getElementById("lineChart").getContext('2d');
lineChart = new Chart(ctxLine, {
type: 'line',
data: {
labels: dates,
datasets: [{
data: ['...'],
backgroundColor: "rgba(52,152,219,0.4)"
}]
},
options: {
elements: {
point: {
borderColor: "rgb(255,255,0)",
backgroundColor: "rgb(255,0,0)"
}
}
}
});
Run Code Online (Sandbox Code Playgroud)
point.borderColor工作正常,但point.backgroundColor只有在我删除第一个backgroundColor字段时才有效。
我自己找到了解决方案。我不知道有不同版本的 chart.js
我正在使用 v2.0 并且存在一个名为的属性 pointBackgroundColor
var ctxLine = document.getElementById("lineChart").getContext('2d');
lineChart = new Chart(ctxLine, {
type: 'line',
data: {
labels: dates,
datasets: [{
data: ['...'],
backgroundColor: "rgba(52,152,219,0.4)",
pointBackgroundColor: "#fff"
}]
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5901 次 |
| 最近记录: |