Skip to main content
🌍 Public

Share visualization

Send this visualization to others.

Legend and colors

Public visualization

Legend and colors

0 stars0🌍 Public
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

Comments

Sign in to join the discussion.

MIT Licensed