Skip to main content
100%

Margins and Axes

✓ Published0🌍 Public
Nnicholasgonzalez1
Last edited Jun 22, 2021
Created on Jun 22, 2021

This example presents a horizontal bar chart of 2019 UN population data for the top ten countries, emphasizing the layout margins that separate the plotting area from the axes. The chart uses D3’s `scaleBand` and `scaleLinear` to map country names and population counts into a fixed `svg` coordinate system, with explicit `margin` constants controlling the left, right, top, and bottom spacing. React manages the component state, while the data is loaded via D3’s `csv` helper. The code renders tick marks and labels for the x-axis using `xScale.ticks()` and custom `<g>` elements, with the y-axis labels positioned manually using `yScale.bandwidth()`.

AI-generated description
MIT Licensed

Similar vizzes