Skip to main content
🌍 Public

Share visualization

Send this visualization to others.

d3 Color and Size Legends

Public visualization

Viewing a saved revision (read-only)

955f333e063c4540af692de0bd08a37a

d3 Color and Size Legends

0 stars0🌍 Public
JJohnPaulPagelerJr
Last edited Feb 27, 2019
Created on Feb 26, 2019

This example demonstrates how to build reusable legend components for both color and size scales. Two separate legends are rendered in an SVG: one showing fruit categories as colored circles using a d3 scaleOrdinal, and another displaying a d3 scaleSqrt with five tick values as scaled circles. The colorLegend and sizeLegend functions manage enter/update/exit selections, appending circle and text elements with attributed transforms and offsets. The code relies on d3-selection methods like selectAll, merge, and exit, with styling applied through external CSS classes.

AI-generated description