Shopping App Tester
This example demonstrates the General Update Pattern for handling dynamic data in D3.js v4, rendered as SVG bar charts. The visualization shows how a shopping app's grocery items (banana, eggs, peanut butter) with price values are displayed as horizontal bars whose widths correspond to price. The code uses `d3.scaleBand` for vertical positioning and `d3.scaleLinear` for width scaling, with `selection.merge()` to combine enter and update selections. Timed tests reveal problems: changing a price only updates the bar's width, while removing an item fails to properly update remaining bars, illustrating common update-pattern pitfalls.
AI-generated descriptionThis example shows the General Update Pattern, which is required to create things with D3.js that update with dynamic data.
Part of the video course: D3.js in Motion.
See also: