Skip to main content
๐ŸŒ Public

Share visualization

Send this visualization to others.

d3 Color and Size Legends

Public visualization

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

Comments

Sign in to join the discussion.

MIT Licensed