D3 Course 9: Color and Size Legends
✓ Published0🌍 Public
This example demonstrates interactive color and size legends built with D3 v5, rendered as SVG. It shows categorical color encoding for fruit types (apple, lemon, lime, orange) using `scaleOrdinal`, and quantitative size encoding for values 0–10 using `scaleSqrt`. The legends are created as reusable components via `colorLegend` and `sizeLegend` functions, which compute tick values from the size scale and position circles with text labels. Styling is applied through external CSS, with the SVG canvas sized at 960×500.
AI-generated descriptionData Visualization with D3 Course; <b>Color and Size Legends</b><br>
<table> <th align="left">Topics</th> <tr> <td> <ul> <li><b>Create a color lengend component</b></li> <li><b>Encoding area using a square root scale</b></li> <li><b>Computing ticks from size scale</b></li> <li><b>Creating a size legend component</b></li> <li><b>Tweaking the styles</b></li> </ul> </td> </tr> </table>MIT Licensed