如何改变圆环图的厚度,使用ChartJs.?

jyztefdp  于 2022-11-06  发布在  Chart.js
关注(0)|答案(7)|浏览(196)

如何使用ChartJs改变圆环图的粗细

tvokkenx

tvokkenx1#

从版本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版本说明中的文档
甜甜圈cutoutPercentage已重命名为cutout,并接受以数字形式表示的像素和以%结尾的字符串形式表示的百分比。

yc0p9oo0

yc0p9oo02#

var options = {        
     cutoutPercentage: 70
};
ghhkc1vu

ghhkc1vu3#

使用percentageInnerCutout,例如:

var options = {        
    percentageInnerCutout: 40
};
myNewChart = new Chart(ct).Doughnut(data, options);

演示:jsFiddle

mwngjboj

mwngjboj4#

如果您正在通过ng2-charts使用chart.js进行Angular,则需要在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 directivesconfig options for the [options] directive的函数

1mrurvl1

1mrurvl15#

自版本3起,该字段已重命名为cutout
自版本3起,字段已重命名为剪切块,可按如下方式使用。
50% -甜甜圈,0 -馅饼
可以这样使用
cutout description

var option = {
    cutout:40
}

https://www.chartjs.org/docs/latest/charts/doughnut.html

jogvjijk

jogvjijk6#

我想补充一下如何在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)
    }]
  }
});}
ego6inou

ego6inou7#

对于vue-chartjs(使用Nuxt测试),如果设置选项不起作用,请尝试:
图表.默认值.圆环图.剪切百分比= 80
请注意,它将更改所有的圆环剪切块。

相关问题