d3js Exercice 4 - selection, data
This example demonstrates a basic data join with D3.js v4, where an array of five numeric values drives the widths of five horizontal bars. The visualization shows how selection and data binding work by pairing each number with a `<div>` element, applying a CSS class and dynamic pixel widths based on the data. The code uses `d3.select` and `selectAll` to target the container, then the `.data()` method to bind the array, followed by `.attr()` and `.style()` to update the bars. Commented exercises hint at extending the example with `.enter()` and `.exit()` for dynamic element creation and removal, though the visible implementation only performs the initial update. The static bars, with heights and margins set via CSS, render from the hardcoded dataset.
AI-generated description