O'Reilly logo

Data Visualization: Representing Information on Modern Web by Swizec Teller, Ændrew Rininsland, Simon Timms, Andy Kirk

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Baking a fresh 'n' delicious pie chart

The preceding bar chart reveals that Ed Miliband received the most donations during this period. Let's find out who's making him so popular.

We are going to use the pie chart layout to cut the donations to The Rt Hon Edward Miliband MP into slices, showing how many donations he got from each donor. After filtering the dataset for donations going to Miliband, we have to categorize the entries by givers, and finally we feed them into the pie chart layout to generate a pie chart.

We can use the histogram layout to put data into bins depending on the DonorName property. Let's add a function to helpers.js:

export function binPerName (data, name) { let nameIds = nameId(data, name); let histogram = d3.layout.histogram() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required