The Margin convention
✓ Published1🌍 Public
This example demonstrates how D3’s margin convention works by rendering a horizontal bar chart of the top ten countries by 2020 population estimates from the UN World Population Prospects 2019 dataset. The chart uses a React component with `d3.csv` to load data, `scaleBand` for the categorical y-axis, and `scaleLinear` for the x-axis. An outer SVG with fixed width and height contains a translated group element (`g`) that positions the bars inside the margin-defined inner area, which is computed by subtracting the top, right, bottom, and left margin values from the outer dimensions.
AI-generated descriptionMIT Licensed