Skip to main content
Public

Share visualization

Loading preview…

Responding to Resize

vizhub.com

Shared links may look like this on X, LinkedIn, Slack, and Discord.

Before sharing, review the publishing checklist.

Choose how to deliver this visualization

LinkedIn caption

LinkedIn may not keep text supplied by the share sheet. Copy the caption and paste it into the post if needed. You can tag the VizHub company page when posting.

More options

Embed on a websiteCopy iframe embed code
Download & exportPNG, HTML, source ZIP

Responding to Resize

1
BBlackTecno
Last edited Nov 11, 2019
Created on Nov 11, 2019

This example demonstrates how a D3.js visualization can automatically adapt to changes in the browser window’s size. Using CSS to fill the page, the chart extracts its container’s client dimensions and redraws the SVG element accordingly. The code employs `d3.select` and attributes like `attr("width")` to resize the graphic, then draws two intersecting lines forming an X with `style("stroke", "green")`. A `window.addEventListener("resize", redraw)` callback triggers the redraw whenever the viewport changes, ensuring the visualization remains correctly scaled.

AI-generated description

Comments

Sign in to join the discussion.

MIT Licensed