How to draw a circle sector on an html5 canvas?

99封情书 提交于 2020-01-21 02:53:45

问题


I'm trying to make a sort of pie-chart shape on a canvas element, however I can't seem to find any function that does this by itself. I only seem to be able to draw full circles and segments. Is there an easy way to do this?

(See also: Wikipedia on circle terminology)


回答1:


The following should work:

context.moveTo(cx,cy);
context.arc(cx,cy,radius,startangle,endangle);
context.lineTo(cx,cy);
context.stroke(); // or context.fill()

with cx, cy being the center of the arc.



来源:https://stackoverflow.com/questions/6230363/how-to-draw-a-circle-sector-on-an-html5-canvas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!