更改chart.Js中甜甜圈图的中心颜色

Change the Center color of doughnut chart in Chart.Js

本文关键字:颜色 甜甜圈 chart Js 更改      更新时间:2023-09-26

有办法更改Chart.Js中中间圆圈的颜色吗?我好像在他们的文件上找不到?

背景是透明的。我想你真的不能给中间的圆圈上色。。主要选项是在画布或图表上放置背景色,但所有空白都将着色。

其透明,采用背景色

使用chart.js 3.8

const colorcenter = {
  id: 'colorcenter',
  beforeDraw(chart, args, options) {
    const {ctx, chartArea: {top, right, bottom, left, width, height}} = chart;
    const radius = chart._metasets[0].controller.innerRadius;
    const x = chart.getDatasetMeta(0).data[0].x;
    const y = chart.getDatasetMeta(0).data[0].y
    ctx.arc(x, y, radius, 0, 2 * Math.PI);
    ctx.fillStyle = options.backgroundColor;
    ctx.fill();
  }
}