【发布时间】:2014-01-27 15:27:15
【问题描述】:
如何改变圆环图的粗细,使用ChartJs
【问题讨论】:
-
尝试在 Doughnut.defaults 中使用 percentInnerCutout : 50。它应该改变厚度。
-
您应该接受提供者的回答;它似乎回答了你的问题:)
标签: javascript chart.js
如何改变圆环图的粗细,使用ChartJs
【问题讨论】:
标签: javascript chart.js
从第 2 版开始,该字段已重命名为 cutoutPercentage。
切除百分比
数字 50 - 代表甜甜圈,0 - 代表馅饼
图表从中间切掉的百分比。
可以这样使用
var options = {
cutoutPercentage: 40
};
更多细节在这里 http://www.chartjs.org/docs/#doughnut-pie-chart-chart-options
更新:从第 3 版开始
var options = {
cutout: 40
};
根据 3.x 发行说明中的文档
Doughnut
cutoutPercentage已重命名为cutout并接受像素作为数字和百分比作为以%结尾的字符串。
【讨论】:
weight (chartjs.org/docs/latest/charts/doughnut.html#styling)
我想添加如何在 React 中实现这一点。
this.myChart = new Chart(this.chartRef.current, {
type: 'doughnut',
options: {
cutout:120
},
data: {
labels: this.props.data.map(d => d.label),
datasets: [{
data: this.props.data.map(d => d.value),
backgroundColor: Object.values(CHART_COLORS)
}]
}
});}
【讨论】:
自版本 3 起,该字段已重命名为 cutout。
从版本 3 开始可以这样使用,该字段已重命名为 cutout。
50% - 用于甜甜圈,0 - 用于馅饼
可以这样使用
var option = {
cutout:40
}
【讨论】:
如果您通过ng2-charts 为Angular 使用chart.js,您可以在您的component.html 文件中执行类似的操作:
// component.html file
<canvas baseChart [options]='chartOptions'>
</canvas>
// Do note that other required directives are missing in this example, but that I chose to highlight the 'options' directive
在你的 component.ts 文件中做这样的事情:
//component.ts file
chartOptions = {
cutoutPercentage: 80
};
有用的信息来源:available chart directives 和 config options for the [options] directive
【讨论】:
var options = {
cutoutPercentage: 70
};
【讨论】:
使用,percentageInnerCutout,喜欢:
var options = {
percentageInnerCutout: 40
};
myNewChart = new Chart(ct).Doughnut(data, options);
演示::jsFiddle
【讨论】:
percentageInnerCutout 中提到的任何属性,现在是cutoutPercentage。参考chartjs.org/docs/latest/charts/doughnut.html