Javascript Chart.js数据背景色覆盖点背景色
我和你一起工作。我有一个特定颜色的数据行。我希望这些数据线的点采用不同的颜色。根据文档,您可以使用Javascript Chart.js数据背景色覆盖点背景色,javascript,chart.js,Javascript,Chart.js,我和你一起工作。我有一个特定颜色的数据行。我希望这些数据线的点采用不同的颜色。根据文档,您可以使用Chart.defaults.global.elements.point.backgroundColor var ctxLine = document.getElementById("lineChart").getContext('2d'); lineChart = new Chart(ctxLine, { type: 'line', data: { labels: dates,
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)"
}
}
}
});
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"
}]
}
});
point.borderColor
工作正常,但是point.backgroundColor
只有在删除第一个backgroundColor
字段时才工作。它看起来像Chart.defaults.global.elements.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)"
}]
},
options: {
elements: {
point: {
borderColor: "rgb(255,255,0)",
backgroundColor: "rgb(255,0,0)"
}
}
}
});
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"
}]
}
});
你救了我,伙计!