Skip to main content
100%

The margin convention

✓ Published1🌍 Public
Kkragovic
Last edited Mar 30, 2021
Created on Mar 30, 2021

This example demonstrates the margin convention for D3 bar charts by displaying the top 10 countries by 2020 population from a UN dataset. The React component loads CSV data via d3.csv, then uses d3.scaleLinear and d3.scaleBand to map population values to bar widths and country names to vertical positions. An SVG group element translates the chart area by the specified margins, while React state and useEffect manage the asynchronous data loading and re-rendering. The chart shows horizontal bars within a fixed 960×500 viewport, with calculated inner dimensions accounting for the margin object.

AI-generated description

A program that loads in some data using D3 utilities, and uses React state to keep track of the data.

MIT Licensed

Similar vizzes