Skip to main content
🌍 Public

Share visualization

Send this visualization to others.

color and size legends

Public visualization

Viewing a saved revision (read-only)

0b879cbcd4654023a7b746a56075c2f3

color and size legends

0 stars1🌍 Public
Aakshayms0
Last edited Nov 3, 2022
Created on Nov 3, 2022
Forked from HTML Starter

This example demonstrates reusable D3.js legend components for mapping ordinal color scales and continuous size scales. The color legend displays four fruit categories using `d3.scaleOrdinal`, while the size legend uses `d3.scaleSqrt` to visualize values from 0 to 10 with proportional circle radii. Both legends render as SVG groups with circles and text labels, using a data-join pattern for enter/update/exit transitions. The `colorLegend` and `sizeLegend` functions illustrate how to build modular, configurable legend components for scatterplots or choropleth maps.

AI-generated description