🌍 Public
Viewing a saved revision (read-only)
f3f78b2c29804b8182bbb23c39ac5f23
Legend and colors
Ppaularl
Last edited Jan 28, 2020
Created on Jan 28, 2020
This example demonstrates how to build reusable legends for mapping data values to visual encodings. A color legend uses an ordinal scale with fruit names and distinct hues, while a size legend applies a square-root scale to represent numeric ticks with circles of varying radii. The code defines `d3.scaleOrdinal()` and `d3.scaleSqrt()` with SVG rendering, and updates legends through enter/merge/exit selections. Both legends are generated as reusable functions called via `.call()`, with circles and text positioned using `spacing` and `textOffset` parameters.
AI-generated description