20

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)

dsavi
  • 1,723
  • 3
  • 12
  • 8

1 Answers1

39

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.

MartinStettner
  • 28,719
  • 15
  • 79
  • 106