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

0
LLittledevil7
Last edited Apr 15, 2020
Created on Apr 15, 2020

This example shows a bar chart of population by country that redraws its X-shaped guide lines whenever the browser window is resized. The code uses `clientWidth` and `clientHeight` to extract the computed CSS dimensions of the chart container, then sets the SVG’s `width` and `height` attributes accordingly. It employs a `window.addEventListener("resize", redraw)` to trigger the update. The bar chart itself is built with `d3.scaleLinear`, `d3.scaleBand`, `d3.axisLeft`, and `d3.axisBottom`, using population data loaded from a CSV file.

AI-generated description

Comments

Sign in to join the discussion.

MIT Licensed