Color class is used wherever color needs to be specified in amCharts 5. It provides methods for creating, converting, and manipulating colors.
Creating Colors
color()
Color value in various formats:
"#f00"- Short hex"#ff0000"- Full hex"rgb(255, 0, 0)"- RGB string"rgba(255, 0, 0, 1)"- RGBA string0xff0000- Hex number
A Color object
Color Class
Properties
hex
Color numeric value.
r
Value of color’s R (red) channel (0-255).
g
Value of color’s G (green) channel (0-255).
b
Value of color’s B (blue) channel (0-255).
Instance Methods
toCSS()
rgba(r, g, b, a) string.
Opacity value (0-1)
CSS color string in rgba format
toCSSHex()
#rgb string.
CSS color string in hex format
toHSL()
Opacity value (0-1)
Object containing HSL values
toString()
Hex color string
Static Methods
Color.fromHex()
Hex color number (e.g., 0xff0000)
New Color object
Color.fromRGB()
Red value (0-255)
Green value (0-255)
Blue value (0-255)
New Color object
Color.fromString()
Hex color string (e.g., “#ff0000”)
New Color object
Color.fromCSS()
CSS color string (e.g., “rgba(255, 0, 0, 1)”)
New Color object
Color.fromHSL()
Hue value (0-360)
Saturation value (0-1)
Lightness value (0-1)
New Color object
Color.fromAny()
Source value in any supported format
New Color object
Color.alternative()
lightAlternative or darkAlternative depending on which one is more contrasting with the color.
Reference color to compare against
Light color option
Dark color option
The more contrasting alternative color
Color.interpolate()
diff) between the two.
Progress value (0-1) between the two colors
Source color
Target color
Interpolation mode
Interpolated color
Color.lighten()
percent value. Use negative value to darken the color.
Source color
Percent to lighten (positive) or darken (negative)
New lightened/darkened color
Color.brighten()
percent value. Use negative value to dim the color.
Source color
Percent to brighten (positive) or dim (negative)
New brightened/dimmed color
Color.saturate()
percent value. Value range is between 0 (fully desaturated) to 1 (full color).
Source color
Saturation level (0-1)
New saturated color