有没有人知道有没有可能改变像图像一样的雷达背景区域,我的海报?
发布于 2018-11-19 08:07:24
我也有同样的问题,看起来文档对这些案例并不友好,我的解决方案基于以下示例:
我的options
对象如下所示:
options: {
...
chartArea: { backgroundColor: 'red' },
...
}
我使用钩子函数beforeDraw
来绘制图表后面的背景色,它看起来像这样:
Chart.pluginService.register({
beforeDraw: chart => {
const { ctx, scale, config } = chart
const { xCenter, yCenter, drawingArea: radius } = scale
ctx.save()
ctx.arc(xCenter, yCenter, radius, 0, Math.PI * 2)
ctx.fillStyle = config.options.chartArea.backgroundColor
ctx.fill()
ctx.restore()
}
});
在beforeDraw
函数中,您可以使用自定义属性捕获options
对象。
您可以查看完整的钩子列表here
发布于 2018-11-13 22:51:35
我假设您使用的是chart.js库中的这个模块
https://www.chartjs.org/docs/latest/charts/radar.html
文档说,您可以在数据集属性上指定它来更改颜色。
data: {
labels: ['Running', 'Swimming', 'Eating', 'Cycling'],
datasets: [{
data: [20, 10, 4, 2],
backgroundColor: 'red'
}]
}
希望这能有所帮助。
https://stackoverflow.com/questions/53283486
复制相似问题