Skip to main content
100%

Create a pie chart with D3 and React

✓ Published0🌍 Public
Llynz09
Last edited Oct 1, 2020
Created on Oct 1, 2020
Forked from D3 and React Hooks

Two React implementations of the same D3 pie chart render side-by-side, showing random data generated with `d3.range` and `Math.random`. The first version uses a function component with the `useEffect` and `useRef` hooks to manage D3 DOM updates, while the second renders SVG elements declaratively through React's JSX. Both use `d3.pie()`, `d3.arc()`, `d3.scaleOrdinal` with `schemeCategory10`, and `d3.format` for labels, with a button triggering new random data.

AI-generated description

Create a pie chart with D3 and React. In my future project, I'd like to make pie charts from data.This is a good chance to prepare for it.I followed this steps to create a pie chart: Generate a function which can generate random data. Create a pie chart with an update function using React class. Create a pie chart with an update function using Hooks. Replace d3 functions with SVG elements. Improve a chart with attributes.

MIT Licensed

Similar vizzes