Skip to content

ColorSet

Type class

Represents a set of colors. Can also generate colors according to set rules.

More info: Colors, Gradients, Patterns for color-related info

Sources

ColorSet can be used (imported) via one of the following packages.

/**
* Import from: "core.ts"
* Use like: am4core.ColorSet
*/
import * as am4core from "@amcharts/amcharts4/core";

Inheritance

ColorSet extends BaseObject.

ColorSet is not extended by any other symbol.

Properties

baseColor

Type ColorDefault new Color({ r: 103, g: 183, b: 220 })

A base color. If there are no colors pre-set in the color list, ColorSet will use this color as a base when generating new ones, applying stepOptions and passOptions to this base color.

currentStep

Type number

Sets current color iteration. You can use this property to skip some colors from iteration. E.g. setting it to 10 will skip first ten colors.

Please note that the number is zero-based.

list

Type Color[]

Sets a list of pre-defined colors to use for the iterator.

Returns current list of colors.

If there are none, a new list of colors is generated, based on various ColorSet settings.

maxLightness

Type numberDefault 0.9

Do not let the "lightness" of generated color to get above this threshold.

minColors

Type numberDefault 20

A number of colors to generate in one "pass".

This setting can be automatically overridden, if ColorSet has a list of pre-set colors. In such case ColorSet will generate exactly the same number of colors with each pass as there were colors in original set.

minLightness

Type numberDefault 0.2

Do not let the "lightness" of generated color to fall below this threshold.

reuse

Type booleanDefault false

Re-use same colors in the pre-set list, when ColorSet runs out of colors, rather than start generating new ones.

saturation

Type numberDefault 1

Saturation of colors. This will change saturation of all colors of color set.

It is recommended to set this in theme, as changing it at run time won't make the items to redraw and change color.

shuffle

Type booleanDefault false

Randomly shuffle generated colors.

startIndex

Type numberDefault 0Since 4.4.9

If set to non-zero value, the ColorSet will start iterating colors from that particular index, not the first color in the list.

step

Type numberDefault 1

An index increment to use when iterating through color list.

Default is 1, which means returning each and every color.

Setting it to a bigger number will make ColorSet next() iterator skip some colors.

E.g. setting to 2, will return every second color in the list.

This is useful, when the color list has colors that are too close each other for contrast.

However, having bigger number will mean that next() iterator will go through the list quicker, and the generator will kick sooner.

stepOptions

Type Partial <IColorSetStepOptions>

Modifications to apply with each new generated color.

wrap

Type booleanDefault true

When colors are generated, based on stepOptions, each generated color gets either lighter or darker.

If this is set to true, color generator will switch to opposing spectrum when reaching minLightness or maxLightness.

E.g. if we start off with a red color, then gradually generate lighter colors through rose shades, then switch back to dark red and gradually increase the lightness of it until it reaches the starting red.

If set to false it will stop there and cap lightness at whatever level we hit minLightness or maxLightness, which may result in a number of the same colors.

4 inherited items
clonedFrom

Type $type.Optional <this>Inherited from BaseObject

Reference to the original object this object was cloned from. We need to keep this so we can disassociate it from source object when this object is disposed.

config

Type objectInherited from BaseObject

Use this property to set JSON-based config. When set, triggers processing routine, which will go through all properties, and try to apply values, create instances, etc.

Use this with caution, as it is a time-consuming process. It's used for initialchart setup only, not routine operations.

id

Type $type.Optional <string>Inherited from BaseObject

Sets the user-defined id of the element.

uid

Type stringInherited from BaseObject

Returns object's internal unique ID.

Methods

constructor()

Returns ColorSet

Constructor

generate(count: number)

Returns void

Generates colors based on the various ColorSet settings.

getIndex(i: number)

Returns Color

Returns a color at specific index in the list.

next()

Returns Color

Returns next color in the list using internal iterator counter.

If step is set to something other than 1, it may return other color than exact next one in the list.

reset()

Returns void

Resets internal iterator.

Calling next() after this will return the very first color in the color list, even if it was already returned before.

5 inherited items
clone(cloneId?: string)

Returns thisInherited from BaseObject

Makes a copy of this object and returns the clone. Try to avoid cloning complex objects like chart, create new instances if you need them.

copyFrom(object: this)

Returns voidInherited from BaseObject

Copies all properties and related data from different element.

dispose()

Returns voidInherited from BaseObject

Destroys this object and all related data.

getCurrentThemes()

Returns ITheme[]Inherited from BaseObject

Returns a list of themes that should be applied to this element. It could either be a list of themes set explicitly on this element, or system-wide.

isDisposed()

Returns booleanInherited from BaseObject

Returns if this object has been already been disposed.

Events

ColorSet does not have any events.