Skip to main content
🌍 Public

Share visualization

Send this visualization to others.

Simple Gradient Fill using D3

Public visualization

Viewing a saved revision (read-only)

f9a777c3e49c4c71bf10859eebf54e3c

Simple Gradient Fill using D3

0 stars1🌍 Public
RRSSBDAE
Last edited Jan 13, 2023
Created on Jan 13, 2023
Forked from JS Bin

Two rectangles demonstrate a reusable D3 linearGradient definition, created in an SVG `defs` element. The first rectangle fills its interior with a diagonal red-to-blue gradient, while the second applies the same gradient to a four-pixel stroke, leaving its fill empty. Using d3-selection and d3 v5, the code sets `x1`, `x2`, `y1`, and `y2` attributes on the gradient and appends offset `stop` elements to control color transitions. The example shows how one gradient can style both fill and stroke in the same SVG scene.

AI-generated description