Dynamic Size Example
This example shows how a D3 visualization can dynamically size itself to fill the page at load time, using an SVG element that matches the dimensions of its container. The code reads the container’s width and height via `clientWidth` and `clientHeight`, then appends an SVG with those exact dimensions. To verify the sizing, it draws two diagonal lines forming an X across the full area, using D3’s data binding and selection methods. The rendering relies on the SVG `line` element and CSS positioning to stretch the container. The visualization does not respond to window resizing after initial load.
AI-generated descriptionThis example shows how to make a D3 visualization that fills up the size of the page at the time it is loaded. This is necessary when, for example, you want to be able to load your visualization into an iFrame that could be any size. This example was created to address this question on the D3 Google Group: Any advice for setting width in iframes with D3?.
Here's a variant that responds to resize.