categoricalColors
categoricalColors picks colors for chart series, legends and tags. It favors colors that stay far apart under normal vision and two red-green color vision simulations, and checks each one against your chart background (3:1 by default, or Lc 45 with APCA).
Example
import { categoricalColors } from 'colore-js';
import { categoricalColors as chartColors } from 'colore-js/fn';
categoricalColors(3).map((color) => color.css()); // ['#1781d4', '#4ba81b', '#ad1a6b']
chartColors(3); // ['#1781d4', '#4ba81b', '#ad1a6b']
Syntax
// colore-js
categoricalColors(count: number, options?: CategoricalColorOptions): Color[]
// colore-js/fn
categoricalColors(count: number, options?: CategoricalColorOptions): string[]
Parameters
Returns
The root function returns Color[]. The /fn version returns CSS strings. With the same options, increasing the count keeps the earlier colors in place.
Throws
A ColorError for invalid colors, unsupported options, an out-of-range count or too few colors at the requested contrast.
Pick colors for a dark dashboard
import { categoricalColors as chartColors } from 'colore-js/fn';
chartColors(5, { background: '#0a0a0a' });
// ['#70b2fb', '#bcdb29', '#ec5480', '#2feac3', '#f86927']
#70b2fb
#bcdb29
#ec5480
#2feac3
#f86927
Check the displayed colors against the real chart background. Labels or line patterns also help readers distinguish nearby series.
Related
- Accessible chart colors for light and dark dashboard palettes
- simulate to preview color vision differences
- scale for ordered values