Skip to main content
🌍 Public

Share visualization

Send this visualization to others.

Margin Convention

Public visualization

Viewing a saved revision (read-only)

c82f45a4dfb14b489aeba2352f5d4c2e

Margin Convention

0 stars1🌍 Public
Rrajamrit-singh
Last edited Jan 31, 2023
Created on Jan 31, 2023
Forked from Bar chart

This example demonstrates the D3 margin convention, a common pattern for reserving space around a chart’s plotting area. It loads UN population data from a CSV file and renders horizontal bars for the top 10 countries, with bar widths proportional to their 2020 population. The React app uses `useState` and `useEffect` to fetch and parse the data with `d3.csv`, then constructs SVG rectangles using `scaleBand` for the y-axis and `scaleLinear` for the x-axis. A margin object defines offsets, and a `<g>` transform aligns the chart within the SVG.

AI-generated description

A program that loads in some data