Overview
Labels in amCharts 5 are text elements that can display static text, dynamic data values, and formatted content. TheLabel class extends Container and provides extensive text styling and formatting capabilities.
Creating Labels
Basic Label
/home/daytona/workspace/source/src/.internal/core/render/Label.ts:250-463
Label with Position
Text Styling
Font Properties
Control typography with various font settings:/home/daytona/workspace/source/src/.internal/core/render/Label.ts:50-83
Color and Opacity
/home/daytona/workspace/source/src/.internal/core/render/Label.ts:24-35
Text with Gradient (v5.10.1+)
/home/daytona/workspace/source/src/.internal/core/render/Label.ts:37-42
Text Alignment
Horizontal Alignment
/home/daytona/workspace/source/src/.internal/core/render/Label.ts:45-47
Baseline Alignment
/home/daytona/workspace/source/src/.internal/core/render/Label.ts:113-114
Text Direction
/home/daytona/workspace/source/src/.internal/core/render/Label.ts:105-109
Line Height and Spacing
Line Height
/home/daytona/workspace/source/src/.internal/core/render/Label.ts:86-88
Baseline Ratio
Control how much of the height goes below the baseline:/home/daytona/workspace/source/src/.internal/core/render/Label.ts:91-95
Oversized Text Handling
Truncation
/home/daytona/workspace/source/src/.internal/core/render/Label.ts:116-150
Text Wrapping
/home/daytona/workspace/source/src/.internal/core/render/Label.ts:127-131
Fitting
Scale text to fit available space:/home/daytona/workspace/source/src/.internal/core/render/Label.ts:153-159
Hiding
Maximum Characters
Limit text length (v5.7.2+):/home/daytona/workspace/source/src/.internal/core/render/Label.ts:220-227
Data Binding
Populate Text from Data
Use placeholders to insert data values:/home/daytona/workspace/source/src/.internal/core/render/Label.ts:162-167
Getting Populated Text
/home/daytona/workspace/source/src/.internal/core/render/Label.ts:444-451
Text Formatting
Inline Formatting
By default, labels support rich text formatting:/home/daytona/workspace/source/src/.internal/core/render/Label.ts:170-175
Shadows
Add shadow effects to labels:/home/daytona/workspace/source/src/.internal/core/render/Label.ts:178-217
Axis Labels
Customizing Axis Labels
/home/daytona/workspace/source/src/.internal/charts/xy/axes/AxisLabel.ts:1-463
Hide Axis Labels
Series Labels
Data Labels on Columns
Data Labels on Line Series
Accessibility
ARIA Labels
Provide screen reader text:Getting Accessible Text
/home/daytona/workspace/source/src/.internal/core/render/Label.ts:453-461
HTML Labels
Use HTML content instead of canvas text:Performance Considerations
Reusing Labels
Limiting Visible Labels
Best Practices
Use Appropriate Font Sizes
Use Appropriate Font Sizes
Choose font sizes that are readable across devices:
Handle Oversized Text
Handle Oversized Text
Always specify how to handle text that doesn’t fit:
Consider Accessibility
Consider Accessibility
Provide ARIA labels for screen readers:
Use Data Binding
Use Data Binding
Enable populateText when showing dynamic data:
Apply Consistent Styling
Apply Consistent Styling
Define style constants for consistency:
Related
Tooltips
Display contextual information on hover
Legends
Create interactive legend labels