Overview
Legends in amCharts 5 provide a visual guide to chart series, allowing users to identify different data sets and interact with them. TheLegend class extends Series and automatically creates legend items for chart components.
Creating Legends
Basic Legend
/home/daytona/workspace/source/src/.internal/core/render/Legend.ts:131-486
Legend Position
Legend Layout
Legend Data
Adding Series
Custom Legend Data
/home/daytona/workspace/source/src/.internal/core/render/Legend.ts:260-401
Legend Markers
Default Markers
By default, legends mimic the appearance of chart elements:/home/daytona/workspace/source/src/.internal/core/render/Legend.ts:80-85
Simple Square Markers
Customizing Marker Rectangles
/home/daytona/workspace/source/src/.internal/core/render/Legend.ts:241-257
Customizing Markers Container
/home/daytona/workspace/source/src/.internal/core/render/Legend.ts:177-194
Legend Labels
Customizing Label Appearance
/home/daytona/workspace/source/src/.internal/core/render/Legend.ts:199-215
Value Labels
Show current values next to legend items:/home/daytona/workspace/source/src/.internal/core/render/Legend.ts:220-236
Custom Label Text
/home/daytona/workspace/source/src/.internal/core/render/Legend.ts:87-104
Legend Containers
Item Containers
Customize the container for each legend item:/home/daytona/workspace/source/src/.internal/core/render/Legend.ts:146-172
Disabled State
Style legend items when their series is hidden:Interaction
Click Target
Control which part of legend item is clickable:/home/daytona/workspace/source/src/.internal/core/render/Legend.ts:106-115
Hover Effects
Scrollable Legends
Make legends scrollable when they have many items:Real-World Examples
Pie Chart Legend
Multi-Series XY Chart Legend
Legend with Icons
Heat Legend
For map charts with value-based coloring:Styling Examples
Modern Legend
Compact Legend
Best Practices
Position Appropriately
Position Appropriately
Place legends where they don’t obscure data:
Use Clear Labels
Use Clear Labels
Ensure legend labels are descriptive:
Limit Legend Items
Limit Legend Items
Too many items can overwhelm users:
Match Visual Style
Match Visual Style
Keep legend style consistent with chart:
Enable Interaction
Enable Interaction
Allow users to toggle series visibility:
Accessibility
ARIA Support
Legends automatically support accessibility:/home/daytona/workspace/source/src/.internal/core/render/Legend.ts:422-435
Related
Labels
Learn about text formatting and label styling
Colors
Customize legend marker colors