如何在html5画布上绘制一个圆形扇区? [英] How to draw a circle sector on an html5 canvas?

查看:252
本文介绍了如何在html5画布上绘制一个圆形扇区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在canvas元素上做一个饼图形状,但是我似乎找不到任何这样做的函数。我只是似乎能够绘制完整的圆和段。有没有简单的方法来做到这一点?

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?

(另见:维基百科的圈子术语

推荐答案

以下应该可以工作:

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

cx cy 作为弧的中心。

这篇关于如何在html5画布上绘制一个圆形扇区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆