Skip to main content
100%

Color & Size Legends

✓ Published1🌍 Public
AAmar Nath Yogi
Last edited Jan 31, 2020
Created on Jan 22, 2020

This example demonstrates two types of chart legends: a color legend mapping ordinal data (apple, orange, lemon) to a d3.scaleOrdinal color scale, and a size legend using d3.scaleSqrt to map a numeric range from 0 to 10 to circle radii. Both legends are rendered as SVG groups, with each tick containing a circle and label. The code utilizes d3.selection, d3.transition, and the .merge() API to animate legend updates over 1000ms, shrinking exiting circles and repositioning entries when the underlying scales change. The size legend positions its ticks horizontally, offsetting each by its radius to avoid overlap.

AI-generated description
MIT Licensed

Similar vizzes