gpt4 book ai didi

javascript - Chart.js(圆环图)中的内半径没有改变

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:40:53 25 4
gpt4 key购买 nike

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

enter image description here

这是我的代码

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
});
}

最佳答案

您应该在 options 对象中使用 percentageInnerCutout 属性

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

你也可以查看这个问题How to vary the thickness of doughnut chart, using ChartJs.?

P.S. 据我了解这取决于版本,所以

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

否则使用percentageInnerCutout

关于javascript - Chart.js(圆环图)中的内半径没有改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43524490/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com