Skip to main content
100%

Dynamic Size Example

✓ Published0🌍 Public
Aadamfknapp
Last edited Oct 10, 2017
Created on Oct 9, 2017

This example demonstrates a dynamic D3 v4 visualization that automatically resizes to fill the browser window, redrawing on any window resize event. It renders a set of horizontal line segments with end caps and black circular dots positioned proportionally to the current viewport dimensions, using an SVG container styled with CSS `position: fixed`. The code extracts `clientWidth` and `clientHeight` from the chart div, then updates the SVG’s width, height, and element coordinates via data joins and `.merge()`. The visualization responds live to user window adjustments, as seen in the full-screen demo.

AI-generated description

This example shows how to make a D3 visualization that fills up the size of the page at the time it is loaded AND whenever the page is resized by the user. This is necessary when, for example, you want to be able to load your visualization "full screen" and give users the ability to size the window however they want to. This example was created to address this question on the D3 Google Group: Any advice for setting width in iframes with D3?.

To experience the resize behavior, run this example full-screen and resize the browser.

<!-- Start of SimpleHitCounter Code --> <div align="center"><img src="http://simplehitcounter.com/hit.php?uid=2221531&f=16777215&b=0" border="0" height="18" width="83"></div> <!-- End of SimpleHitCounter Code -->

forked from <a href='http://bl.ocks.org/curran/'>curran</a>'s block: <a href='http://bl.ocks.org/curran/3a68b0c81991e2e94b19'>Responding to Resize</a>

This is a reproduction of the 'Position on Common Scale' block created by Adam Knapp and availible at https://bl.ocks.org/adamfknapp/7e78932767a8281a7e5f9624aa3bcb6c/684c451700e8e2b0d22f5728530a9ce2832a5731

mit Licensed

Similar vizzes