Skip to main content
🌍 Public

Share visualization

Send this visualization to others.

Color and size legend

Public visualization

Viewing a saved revision (read-only)

2a0b161db4014de3b6f34799d9aca624

Color and size legend

0 stars0🌍 Public
ZZhengyan Yu
Last edited Apr 25, 2020
Created on Apr 25, 2020

This example demonstrates a custom color legend for ordinal data, showing categories as colored circles with matching labels. The legend displays two fruit categories, apple and lemon, each assigned a distinct color via `d3.scaleOrdinal`. The visualization uses D3 v5 with an SVG rendering approach, where the `colorLegend` function appends circle and text elements to the SVG canvas. Labels are positioned below the circles, and all elements are centered vertically using the SVG height attribute. The code also includes transition handling for updating the legend dynamically.

AI-generated description