Skip to main content
🌍 Public

Share visualization

Send this visualization to others.

The margin convention

Public visualization

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

Comments

Sign in to join the discussion.

MIT Licensed