Skip to main content
100%

Drawing SVG rect with D3

✓ Published0🌍 Public
AAlina Sul
Last edited Mar 21, 2020
Created on Mar 21, 2020
Forked from HTML Starter

This example demonstrates two ways to render a blue SVG rectangle: one statically defined directly in HTML markup, and another generated dynamically using D3’s selection and data-join methods. The code uses `d3.select` to append an `svg` element to the body, then chains an `append('rect')` call to set its width and height attributes via `.attr()` and its fill color via `.style()`. A hand-written `<rect>` element appears above as a visual comparison, while the D3-generated rectangle is rendered below, with both sharing the same dimensions and color.

AI-generated description

A bare minimum HTML page.

See also React Starter.

MIT Licensed

Similar vizzes