Skip to main content
100%

Making a Bar Chart in React & D3

✓ Published0🌍 Public
CChaz
Last edited Jan 19, 2022
Created on Jan 18, 2022

This example shows a horizontal bar chart of the top 10 most populous countries for 2020, using a dataset from the UN Population 2019 CSV loaded via `d3.csv`. React’s `useState` and `useEffect` hooks manage the asynchronous data fetch and re-render the bars once loaded. D3’s `scaleBand` and `scaleLinear` map country names and population values to SVG `rect` coordinates and widths, with each bar’s height derived from `yScale.bandwidth()`. The chart renders purely as SVG inside a React component.

AI-generated description

A program that load in using D3 utilities, and uses React state to render the data as a bar chart!

MIT Licensed

Similar vizzes