利用chart.datasets[0].points[4].fillColor = "red";
类型代码的解决方案不再适用于 chart.js v2+。
但是,pointBorderColor 等数据集属性接受数组,这非常有用。这使您可以创建一组颜色(或其他属性),并且可以为特定数据点设置不同的属性。您也可以稍后访问数组中的属性并进行更改。
例子:
data: {
labels: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ],
datasets: [
{
fill: false,
lineTension: 0.4,
backgroundColor: [ "rgba(117, 201, 196,0.4)", "rgba(117, 201, 196,0.4)", "rgba(117, 201, 196,0.4)", "rgba(117, 201, 196,0.4)", "rgba(117, 201, 196,0.4)", "rgba(117, 201, 196,0.4)", "rgba(117, 201, 196,0.4)", "rgba(117, 201, 196,0.4)", "rgba(117, 201, 196,0.4)", "rgba(117, 201, 196,0.4)" ],
borderColor: "rgba(117, 201, 196, 0.8)",
borderCapStyle: 'butt',
borderDash: [],
borderDashOffset: 0.0,
borderJoinStyle: 'miter',
pointBorderColor: [ "rgb(117, 201, 196)", "rgb(117, 201, 196)", "rgb(117, 201, 196)", "rgb(117, 201, 196)", "rgb(117, 201, 196)", "rgb(117, 201, 196)", "rgb(117, 201, 196)", "rgb(117, 201, 196)", "rgb(117, 201, 196)", "rgb(117, 201, 196)" ],
pointBackgroundColor: [ "#fff", "#fff", "#fff", "#fff", "#fff", "#fff", "#fff", "#fff", "#fff", "#fff" ],
pointBorderWidth: 1,
pointHoverRadius: 5,
pointHoverBackgroundColor: [ "rgb(117, 201, 196)", "rgb(117, 201, 196)", "rgb(117, 201, 196)", "rgb(117, 201, 196)", "rgb(117, 201, 196)", "rgb(117, 201, 196)", "rgb(117, 201, 196)", "rgb(117, 201, 196)", "rgb(117, 201, 196)", "rgb(117, 201, 196)" ],
pointHoverBorderColor: "rgba(220,220,220,1)",
pointHoverBorderWidth: 2,
pointRadius: [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ],
pointHitRadius: 10,
data: [ 1, 3, 6, 12, 18, 28, 17, 10, 3, 2 ],
spanGaps: false
}
]
}