A pie layout generator is a preprocessing function: it converts numeric data into annotated slice descriptors containing each slice’s start and end angles. It prepares data for drawing but does not draw the chart itself. section 5.0 section 5.4
Create pie or donut data in three practical steps:
- Format the input as numbers or objects. Object data preserves information such as a music format alongside its sales value. section 5.1.2
- Initialize the generator and identify the numeric field with a value accessor: const pieGenerator = d3.pie().value(d => d.sales); section 5.4
Sales by music format
For 1975, format sales can begin as [8061.8, 2770.4, 469.5, 0, 0, 0, 48.5]. Converting these values into objects such as { format: "vinyl", sales: 8061.8 } preserves slice identity. The resulting descriptors supply angles to an arc generator, which calculates SVG path d attributes for the donut chart. section 5.1.4
