Skip to main content
🌍 Public

Share visualization

Send this visualization to others.

Color Legends

Public visualization

Color Legends

0 stars1🌍 Public
AAli Ahmed
Last edited Dec 5, 2018
Created on Dec 5, 2018

This example shows a reusable color legend component that maps ordinal categories to colored circles with labels. Using d3.scaleOrdinal, it defines a domain of fruit types and a range of colors, rendering each category as a red or yellow circle positioned horizontally with a text label below. The code exports a colorLegend function that leverages D3’s enter, merge, and exit selections to update groups dynamically, while the SVG is populated via d3.select and custom xPosition and height-based transforms.

AI-generated description

Comments

Sign in to join the discussion.

MIT Licensed