Skip to main content
🌍 Public

Share visualization

Send this visualization to others.

Color and size legends

Public visualization

Color and size legends

0 stars2🌍 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

Comments

Sign in to join the discussion.

MIT Licensed