Skip to main content
100%

Color and Size Legend

✓ Published0🌍 Public
KKazushige Okuma
Last edited Sep 30, 2019
Created on Sep 25, 2019

This example demonstrates two custom legend components built with D3 v5: a categorical color legend for fruit categories and a quantitative size legend for a numeric scale. The color legend maps ordinal domain values to a range of colors using `scaleOrdinal`, while the size legend uses `scaleSqrt` to translate tick values into circle radii. Both legends render as SVG groups with circles and text labels, with spacing and offsets applied via `attr("transform")` and positioned within an `svg` element.

AI-generated description
MIT Licensed

Similar vizzes