Drawing Arcs

D3 can generate the arcs required for drawing a pie chart.

We are going to start drawing the arcs of the pie. D3 comes with a function for helping us draw the arcs. First, we need to decide what the radius of the overall pie will be. The radius is the distance from the center of the circle to the edge.

Setting the radius

The pie should take up the entire space of the container. We can calculate the radius by dividing the width of the container by two. In the script, we are going to store the radius at the location where we set the dimensions. We will define a variable called radius.

Get hands-on with 1400+ tech skills courses.