Skip to main content
🌍 Public

Share visualization

Send this visualization to others.

Color and Size Legends

Public visualization

Viewing a saved revision (read-only)

690669f70e66400c8f02e83153110fef

Color and Size Legends

0 stars0🌍 Public
NNita
Last edited Sep 24, 2018
Created on Sep 24, 2018

This example demonstrates how legends can visualize both ordinal color scales and quantitative size scales. A color legend maps fruit names to distinct hues using `d3.scaleOrdinal`, while a size legend translates a numeric range into varying circle diameters via `d3.scaleSqrt`. Both legends are constructed as reusable functions that append SVG `<g>` groups and circles, using D3’s selection and merge patterns to handle updates. Text labels accompany each circle, positioned relative to the circle’s radius.

AI-generated description