Skip to main content
🌍 Public

Share visualization

Send this visualization to others.

Responding to Resize

Public visualization

Viewing a saved revision (read-only)

84a8932d83fc4b1c92d69b198069eb23

Responding to Resize

0 stars0🌍 Public
VVineel Gannu
Last edited Jul 16, 2020
Created on Jul 16, 2020

This example demonstrates how to make a visualization respond to browser resizing by redrawing SVG content to match the container’s current dimensions. The code uses D3 v5 to create a blue X composed of two `<line>` elements, whose coordinates are recomputed whenever the window fires a resize event. It reads the computed width and height from the chart `<div>` using `clientWidth` and `clientHeight`, then updates the SVG’s `width` and `height` attributes accordingly. The rendering relies on standard D3 data joins and attribute setters.

AI-generated description