Skip to main content
Public

Share visualization

Loading preview…

Color and size legend

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 legend

0
YYedrup
Last edited Mar 22, 2020
Created on Mar 21, 2020

This example demonstrates two custom D3 legend components rendered as SVG: a color legend for categorical values and a size legend for continuous quantitative values. The color legend uses `scaleOrdinal` to map fruit names to distinct colors, while the size legend employs `scaleSqrt` to translate numeric ticks into circle radii. Both legends rely on D3 v5’s data join pattern with enter/merge/exit selections, and the size legend filters out zero values from `ticks()` while setting explicit spacing and circle fill properties.

AI-generated description

Comments

Sign in to join the discussion.

MIT Licensed