Skip to main content
100%

Color and Size Legends

✓ Published0🌍 Public
CClaudio Barone
Last edited Apr 3, 2020
Created on Apr 3, 2020

This example demonstrates how to create custom color and size legends for D3 visualizations. The color legend displays four categorical fruits using a d3.scaleOrdinal with distinct color ranges, while the size legend uses d3.scaleSqrt to map numeric values from 0 to 10 to circle radii. Both legends are built using reusable functions with enter/merge/exit patterns, rendering SVG groups with circles and text labels. The code uses D3 v5 selection methods and scales to position legend items with configurable spacing and text offsets.

AI-generated description
MIT Licensed

Similar vizzes