Skip to main content
Public

Share visualization

Loading preview…

Color and Size Legends.js

vizhub.com

Shared links may look like this on X, LinkedIn, Slack, and Discord.

Before sharing, review the publishing checklist.

Choose how to deliver this visualization

LinkedIn caption

LinkedIn may not keep text supplied by the share sheet. Copy the caption and paste it into the post if needed. You can tag the VizHub company page when posting.

More options

Embed on a websiteCopy iframe embed code
Download & exportPNG, HTML, source ZIP

Color and Size Legends.js

0
NNeepaB
Last edited Dec 28, 2020
Created on Dec 25, 2020

Two reusable D3 legend components demonstrate how to encode data through color and size. The color legend uses `scaleOrdinal` to map fruit categories to distinct hues, while the size legend uses `scaleSqrt` with tick marks to represent numeric values. Both render as SVG groups with circles and text labels, updating through D3's data join pattern. The examples show how legends can be built using `selection.call` with custom functions and `merge` for enter/update transitions.

AI-generated description

Comments

Sign in to join the discussion.

MIT Licensed