Skip to main content
Public

Share visualization

Loading preview…

Practic 06 | Bowl of Fruit

vizhub.com

Shared links may look like this on X, LinkedIn, Slack, and Discord.

Before sharing, review the publishing checklist.

Choose how to deliver this visualization

LinkedIn caption

LinkedIn may not keep text supplied by the share sheet. Copy the caption and paste it into the post if needed. You can tag the VizHub company page when posting.

More options

Embed on a websiteCopy iframe embed code
Download & exportPNG, HTML, source ZIP

Practic 06 | Bowl of Fruit

1
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.

Comments

Sign in to join the discussion.

MIT Licensed