Skip to main content
🌍 Public

Share visualization

Send this visualization to others.

Colour and Size Legends

Public visualization

Colour and Size Legends

0 stars0🌍 Public
JJordan Chiu
Last edited Feb 13, 2020
Created on Feb 13, 2020

This example demonstrates two reusable legend components for D3 v5 visualizations: an ordinal color legend and a quantitative size legend. The color legend maps fruit categories to distinct colors using `scaleOrdinal`, while the size legend uses `scaleSqrt` to transform numeric values into circle radii. Both components render as SVG groups with tick marks and labels, using data joins and enter/merge/exit patterns for dynamic updates. The size legend generates ticks via the scale’s `ticks` method, filtering out zero, and positions circle centers according to the scaled radius.

AI-generated description

Tutorial!

Comments

Sign in to join the discussion.

MIT Licensed