Skip to main content
๐ŸŒ Public

Share visualization

Send this visualization to others.

Simple Gradient Fill using D3

Public visualization

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

Comments

Sign in to join the discussion.

MIT Licensed