Skip to main content
100%

D3 - using SVG Bounding Box to get the "automatic padding"

✓ Published0🌍 Public
ZZJONSSON
Last edited Oct 22, 2011
Created on Oct 22, 2011

This example demonstrates how to dynamically adjust an SVG chart's viewBox based on the bounding box of its contents. It uses D3.js to render axes, titles, and tick marks, then toggles the y-axis domain between 100 and 999,999,999 every second. After each domain change, the code calls `getBBox()` on the SVG element to compute the new bounding box and updates the `viewBox` attribute, automatically providing padding that accommodates the rescaled axis labels. The animation cycles indefinitely using `setInterval`.

AI-generated description

Similar vizzes