Skip to main content
🌍 Public

Share visualization

Send this visualization to others.

Color and Size Legends

Public visualization

Color and Size Legends

0 stars0🌍 Public
NNico Donovan
Last edited Jul 17, 2020
Created on Jul 16, 2020

This example demonstrates how to create categorical color legends and quantitative size legends using D3.js v5’s `scaleOrdinal` and `scaleSqrt` APIs. The color legend maps fruit names to distinct hues, while the size legend encodes numeric values through circle radii using a square root transformation, with tick marks generated from the scale’s `ticks` method. Both legends are rendered as SVG groups containing circles and text, using the nested general update pattern to handle enter/update/exit transitions efficiently.

AI-generated description

creating a color legend component

encoding area using a square root scale

computing ticks from size scale

creating a size legend component

tweaking the styles

Comments

Sign in to join the discussion.

MIT Licensed