Skip to main content
100%

Color and size legends

✓ Published2🌍 Public
MMaciek Sitkowski
Last edited Sep 3, 2020
Created on Sep 3, 2020

This example demonstrates two types of chart legends rendered side-by-side in SVG. A color legend uses a d3.scaleOrdinal to map fruit names to distinct colors, with circles and text labels offset vertically. A size legend uses d3.scaleSqrt to map a numeric domain to circle radii, filtering out zero, reversing the tick order, and positioning text labels using the scaled radius plus an offset. Both legends are implemented as reusable functions that manage enter/update/exit selections with D3 v5’s data join.

AI-generated description
MIT Licensed

Similar vizzes