Margin Convention
✓ Published1🌍 Public
This example demonstrates the margin convention for chart layout in D3, rendering a horizontal bar chart of the top ten countries by 2020 population from a UN dataset. The chart uses React hooks to load CSV data via `d3.csv` and calculates inner dimensions by subtracting a fixed margin from the SVG’s width and height. Bars are drawn as SVG `<rect>` elements positioned with `d3.scaleBand` for the y-axis and `d3.scaleLinear` for the x-axis, all translated inside a `<g>` group using the margin offsets. The code imports `arc`, `pie`, and `max` from D3, though the example only uses the latter for scaling.
AI-generated descriptionA bare minimum HTML page demonstrating use of CSS and JavaScript.
See also React Starter.
MIT Licensed