简体   繁体   English

Chartjs 甜甜圈图圆角半甜甜圈

[英]Chartjs doughnut chart rounded corners for half doghnut

I am using chartJS library for one of my projects and I need to draw a doughnut chart.我正在为我的一个项目使用 chartJS 库,我需要绘制一个圆环图。 The doughnut chart needs to be a half circle and the sections in it needs to have rounded edges, something like shown below圆环图需要是一个半圆,其中的部分需要有圆边,如下所示

在此处输入图片说明

I could achieve the same for a full circle by referencing this great answer as shown in the codepen below通过参考下面的代码笔中所示的这个很好的答案,我可以在一个完整的圆圈中实现相同的效果

Full circle with rounded edges codepen here带圆角的全圆在这里使用 codepen

But if I change the options to draw a half circle with following options但是,如果我更改选项以使用以下选项绘制半圆

rotation: 1 * Math.PI,
circumference: 1 * Math.PI,

then the calculations seems to go wrong somewhere and the arc circles are placed randomly as shown below然后计算似乎在某处出错,圆弧圆随机放置,如下所示

Problem Code pen here问题代码笔在这里

How can i fix this.我怎样才能解决这个问题。 Please help.请帮忙。 I am stuck.我被困住了。 Thanks谢谢

You should change y translation by factor of 2:您应该将 y 平移更改为 2 倍:

ctx.translate(arc.round.x, arc.round.y*2);

http://jsfiddle.net/alonas/kx6rjy07/ http://jsfiddle.net/alonas/kx6rjy07/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM