Formatting the data for the arc

The reason that our arc() function won't work is the data isn't formatted properly for the function. The arc function that we generated expects the data object to have things like a start angle, an end angle, and so on. Fortunately, D3 can reformat our data so that it will work with our generated arc() function. To do this, we'll generate a pie function that will take a dataset and add the necessary attributes to it for the start angle, end angle, and so on. Add the following just before the code for var path =d3.select('g').selectAll('path')...:

var pie = d3.pie()
    .value(function(d) { return d.count; }) //use the 'count' property each value in the original array to determine how big the piece of pie should ...

Get D3.js Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.