Skip to main content
100%

Color Legends

✓ Published1🌍 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
MIT Licensed

Similar vizzes