Overview
Colors in amCharts 5 are handled through theColor class, which provides a robust set of methods for creating, manipulating, and working with colors across your visualizations.
Creating Colors
Using the color() Helper Function
The simplest way to create a color is using thecolor() helper function:
Using Color Class Methods
TheColor class provides static methods for creating colors from different formats:
/home/daytona/workspace/source/src/.internal/core/util/Color.ts:69-216
Color Properties
Access individual color channel values:Color Manipulation
Lightening and Darkening
Adjust the lightness of colors:/home/daytona/workspace/source/src/.internal/core/util/Color.ts:319-322
Brightening
Adjust the brightness of colors:/home/daytona/workspace/source/src/.internal/core/util/Color.ts:333-336
Saturation
Adjust color saturation (0 = fully desaturated, 1 = full color):/home/daytona/workspace/source/src/.internal/core/util/Color.ts:347-350
Color Interpolation
Create intermediate colors between two colors:/home/daytona/workspace/source/src/.internal/core/util/Color.ts:291-308
Alternative Colors
Get contrasting colors for better visibility:/home/daytona/workspace/source/src/.internal/core/util/Color.ts:272-279
Applying Colors to Chart Elements
Fill Colors
Stroke Colors
Color Sets
ColorSet manages multiple colors and can generate new ones dynamically.Creating a Color Set
/home/daytona/workspace/source/src/.internal/core/util/ColorSet.ts:5-52
Using Color Sets
/home/daytona/workspace/source/src/.internal/core/util/ColorSet.ts:158-188
Color Set with Auto-Generation
When the ColorSet runs out of colors, it automatically generates new ones:/home/daytona/workspace/source/src/.internal/core/util/ColorSet.ts:115-148
Applying ColorSet to Series
Color Conversion
To CSS Strings
/home/daytona/workspace/source/src/.internal/core/util/Color.ts:124-170
To HSL
/home/daytona/workspace/source/src/.internal/core/util/Color.ts:142-149
Best Practices
Use Color Constants
Use Color Constants
Define frequently used colors as constants at the top of your file:
Consider Color Accessibility
Consider Color Accessibility
Use
Color.alternative() to ensure sufficient contrast for text:Reuse Color Sets
Reuse Color Sets
Create a single ColorSet instance and reuse it across multiple series for consistent coloring:
Related
Gradients
Learn how to create linear and radial gradients
Patterns
Apply repeating patterns to chart elements