Skip to main content
100%

Responding to Resize

✓ Published0🌍 Public
Aalicenie
Last edited Jun 15, 2020
Created on Jun 15, 2020

This example demonstrates a responsive SVG chart that continuously updates its dimensions to match the browser window. The visualization draws two diagonal green lines that form an X, with the lines' endpoints recalculated based on the current width and height. The code uses the `d3.select` method to append an SVG element to a fixed-position div, then reads the div’s `clientWidth` and `clientHeight` properties on every window resize event to update the SVG’s `width` and `height` attributes. The redraw function merges new line data with existing elements using D3’s `.merge` method.

AI-generated description
MIT Licensed

Similar vizzes