Chart.js(甜甜圈图)中的内部半径未更改

Zoh*_*ala 3 javascript angularjs chart.js ionic2

我正在使用Chart.js,我想要一个半甜甜圈图,如下图所示。但是我没有改变馅饼的厚度。我尝试了属性innerRadius,但仍然无法正常工作

在此处输入图片说明

这是我的代码

public getHalfDoughnutChart(records) {
    let data = {
       labels: ["Worked Hours","Remaining Hours"],
       datasets: [{
       label: 'Today\'s Worked Hours',
       data: [records.length? records[0].duration.hour: 0,9],
       backgroundColor: [
          'rgba(75, 174, 79, 1)',
          'rgba(255, 255, 255, 0)'
       ]
     }]
 };

    let options = {
      circumference: Math.PI,
      rotation: 1.0 * Math.PI,
      innerRadius: "10%",
      legend: {
        display: false
      },
      layout:{
        padding:40
      }, 
    }

     return this.getChart(this.halfDoughnutCanvas.nativeElement, "doughnut", data, options);
  }



getChart(context, chartType, data, options?) {
   return new Chart(context, {
      type: chartType,
      data: data,
      options: options
   });
}
Run Code Online (Sandbox Code Playgroud)

Leg*_*est 6

您应该percentageInnerCutoutoptions对象中使用属性

let options = {
  circumference: Math.PI,
  rotation: 1.0 * Math.PI,
  percentageInnerCutout: 10,
  legend: {
    display: false
  },
  layout:{
    padding:40
  }, 
}
Run Code Online (Sandbox Code Playgroud)

您还可以检查此问题,如何使用ChartJs改变甜甜圈图的厚度。

PS据我了解,取决于版本,所以

如果Chart.js版本> 2.0使用cutoutPercentage

否则使用 percentageInnerCutout