Skip to main content
🌍 Public

Share visualization

Send this visualization to others.

The margin convention

Public visualization

Viewing a saved revision (read-only)

aca6f56a78d149cf8f443264a6fe90cd

The margin convention

0 stars1🌍 Public
Rrvdv
Last edited Dec 22, 2021
Created on Dec 22, 2021

This example demonstrates the margin convention in D3, a common pattern for reserving space around a chart’s plotting area. It renders a horizontal bar chart of the top 20 countries by 2020 population from a CSV dataset. The code uses React hooks to fetch and parse the data, then applies `d3.scaleBand` and `d3.scaleLinear` to map countries and populations to SVG rectangles. A `<g>` element is translated by the margin offsets, ensuring axes and labels fit neatly within the overall SVG canvas.

AI-generated description