Skip to main content
100%

Colour and Size Legends

✓ Published0🌍 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!

MIT Licensed

Similar vizzes