π Public
The Margin Convention
This example demonstrates the Margin Convention, a fundamental layout pattern for D3 visualizations, using a horizontal bar chart of the ten most populous countries in 2020. The chart loads UN population data via `d3.csv`, then renders SVG rectangles with React components. The visualization shows how margins create an inner plotting area, with `d3.scaleBand` mapping country names to the y-axis and `d3.scaleLinear` scaling population values to the x-axis. The code explicitly calculates `innerHeight` and `innerWidth` by subtracting margins from the total dimensions, and applies the margin offset through an SVG `<g>` transform.
AI-generated descriptionA program that loads in some data about countries population using D3 bar chart, and uses React to render the data.
MIT Licensed
Comments
Sign in to join the discussion.