🌍 Public
Viewing a saved revision (read-only)
b221491f051e439ba8127b7f3a556aea
The Margin Convention
This example demonstrates the margin convention for bar charts, displaying the top 10 countries by 2020 population from a UN dataset. The chart renders horizontal bars using SVG `<rect>` elements, positioned with `d3.scaleBand` for the categorical y-axis and `d3.scaleLinear` for the quantitative x-axis. Data loads asynchronously via `d3.csv` into React state with `useEffect`, while margins are applied through a translated `<g>` group. The visualization shows how to separate chart dimensions from overall SVG size using explicit margin objects.
AI-generated description