Reusable Examples - Pie Chart
This example demonstrates a reusable pie chart built with D3.js v5, following the patterns from Mike Bostock's "Towards Reusable Charts" and the Pro D3.js methodology. It renders two separate pie charts within a single SVG container, using `d3.pie` and `d3.arc` to calculate and draw the slices with an inner radius for a donut effect. The chart includes a title and uses `d3.scaleOrdinal` with the category10 color scheme to distinguish data categories. The code shows a modular structure with separate functions for building the layout, shape, scales, and SVG, allowing the chart to be easily reused with different datasets.
AI-generated descriptionSimple Pie Chart:
A vanilla HTML implementation of a reusable version of tutorials teacher V5 example (https://www.tutorialsteacher.com/d3js/create-pie-chart-using-d3js).
The reusable chart is derived from Mike Bostock's Towards Reusable Charts (https://bost.ocks.org/mike/chart/) as the source of the foundational principles. But uses the ProD3 pattern (Pro D3.js Use D3.js to Create Maintainable, Modular, and Testable Charts by Marcos Iglesias https://www.apress.com/gp/book/9781484252024) as the basis for the charts.
Addtional help from and aknowledgement to:
- Mastering D3.js by Castillo Pablo Navarro. https://www.packtpub.com/web-development/mastering-d3js
- Data Visualization with D3.js Cookbook by Nick Qi Zhu https://www.packtpub.com/product/data-visualization-with-d3-js-cookbook/9781782162162
- Developing A D3.js Edge - Constructing reusable D3 components and charts by Chris Viau Andrew Thornton Ger Hobbelt,Roland Dunn https://www.wileyindia.com/developing-a-d3-js-edge-constructing-reusable-d3-components-and-charts.html.