Skip to main content
100%

Practic 06 | Bowl of Fruit

✓ Published1🌍 Public
Hhimanshucse2012
Last edited Nov 6, 2021
Created on Nov 6, 2021

This example demonstrates the enter-update-exit pattern in D3.js v5 by rendering a row of five red apples as SVG circles. Using `selection.selectAll('circle')` and `selection.data()`, the code binds an array of fruit objects to the DOM, appending circles with `enter().append('circle')` and positioning them via `attr('cx', (d, i) => i * 100 + 60)`. After two seconds, a `setTimeout` removes the last fruit from the array, and the `exit().remove()` method deletes the corresponding circle, showing how D3 handles data-driven updates. The visualization uses a static 960×500 SVG canvas with no interaction.

AI-generated description

Demonstrates fundamental DOM manipulation using D3.js by making a smiley face whose eyebrows move.

MIT Licensed

Similar vizzes