Skip to main content
100%

25. D3 Bar Chart Widths

✓ Published1🌍 Public
Aamakanju@nyit.edu
Last edited Feb 12, 2026
Created on Feb 9, 2026

This example demonstrates a bar chart with dynamic widths and spacing. It renders 20 rectangles in an SVG container, positioning each bar horizontally and calculating its width based on the dataset length with a fixed padding. The chart uses D3.js version 4.5.0, applying the `selectAll`, `data`, and `enter` pattern to bind the array of numbers to SVG `rect` elements. All bars are drawn with a constant height of 100 pixels, and the x-coordinates are computed using the index multiplied by the width divided by the dataset size.

AI-generated description
MIT Licensed

Similar vizzes