Skip to main content
100%

D3: A chart transition with controlled duration (labels, too!)

✓ Published0🌍 Public
深深度碎片
Last edited Aug 1, 2016
Created on Jul 30, 2016

This example demonstrates a bar chart whose values, bar heights, colors, and labels all animate over five seconds after a user clicks the accompanying text. The chart initially displays a set of twenty numeric values as SVG rectangles, with corresponding white text labels positioned above each bar. The code uses D3 v4’s `scaleBand` for the x-axis, `scaleLinear` for the y-axis, and the `transition().duration()` method to smoothly interpolate the `y`, `height`, `fill`, and label text attributes when new data is applied. The dataset is a hardcoded array of numbers, rendered entirely via SVG elements.

AI-generated description

Built with blockbuilder.org

This is an example copied from Interactive Data Visualization for the web.

I updated it with d3.v4.

gpl-3.0 Licensed

Similar vizzes