Categorical color schemes provide discrete colors for qualitative data visualization. These schemes are designed to be maximally distinguishable for representing distinct categories, making them ideal for pie charts, bar charts, and other visualizations where data points belong to separate groups.
The default 10-color categorical scheme, commonly used in D3.js visualizations.
/**
* Default 10-color categorical scheme
* Colors: blue, orange, green, red, purple, brown, pink, gray, olive, cyan
*/
const schemeCategory10: string[];Usage Examples:
import { schemeCategory10 } from "d3-scale-chromatic";
import { scaleOrdinal } from "d3-scale";
// Use with D3 ordinal scale
const colorScale = scaleOrdinal(schemeCategory10);
const colors = ["apple", "banana", "cherry"].map(colorScale);
// Direct array access
const firstColor = schemeCategory10[0]; // "#1f77b4" (blue)
const allColors = schemeCategory10; // Array of 10 colorsProfessional categorical color schemes derived from Cynthia Brewer's ColorBrewer system.
/**
* ColorBrewer Accent scheme - 8 qualitative colors
* Bright, distinct colors suitable for highlighting
*/
const schemeAccent: string[];
/**
* ColorBrewer Dark2 scheme - 8 qualitative colors
* Darker tones for better contrast on light backgrounds
*/
const schemeDark2: string[];
/**
* ColorBrewer Paired scheme - 12 qualitative colors
* Colors arranged in pairs of light/dark variants
*/
const schemePaired: string[];
/**
* ColorBrewer Pastel1 scheme - 9 qualitative colors
* Soft, light colors for subtle differentiation
*/
const schemePastel1: string[];
/**
* ColorBrewer Pastel2 scheme - 8 qualitative colors
* Alternative pastel color palette
*/
const schemePastel2: string[];
/**
* ColorBrewer Set1 scheme - 9 qualitative colors
* Bright, saturated colors for maximum distinction
*/
const schemeSet1: string[];
/**
* ColorBrewer Set2 scheme - 8 qualitative colors
* Medium saturation colors for balanced visibility
*/
const schemeSet2: string[];
/**
* ColorBrewer Set3 scheme - 12 qualitative colors
* Light, desaturated colors for subtle categorization
*/
const schemeSet3: string[];Modern 10-color categorical scheme optimized for contemporary data visualization.
/**
* Observable's 10-color categorical scheme
* Contemporary colors optimized for modern visualizations
*/
const schemeObservable10: string[];Professional 10-color scheme from Tableau visualization software.
/**
* Tableau's 10-color categorical scheme
* Industry-standard colors used in business visualizations
*/
const schemeTableau10: string[];import { schemeCategory10, schemeSet1 } from "d3-scale-chromatic";
import { scaleOrdinal } from "d3-scale";
// Basic ordinal scale
const colorScale = scaleOrdinal(schemeCategory10);
// Scale with explicit domain
const namedColorScale = scaleOrdinal(schemeSet1)
.domain(["primary", "secondary", "tertiary"]);
// Using the scale
const primaryColor = namedColorScale("primary");import { schemePaired, schemeAccent } from "d3-scale-chromatic";
// Get specific colors by index
const headerColor = schemePaired[0];
const accentColor = schemeAccent[2];
// Use entire array for mapping
const categoryColors = categories.map((_, i) => schemePaired[i % schemePaired.length]);import {
schemeCategory10,
schemeSet1,
schemeDark2
} from "d3-scale-chromatic";
// Choose scheme based on category count and design needs
function selectCategoricalScheme(categoryCount, theme = "default") {
if (categoryCount <= 8 && theme === "dark") return schemeDark2;
if (categoryCount <= 9 && theme === "bright") return schemeSet1;
return schemeCategory10; // Default fallback
}| Scheme | Color Count | Characteristics |
|---|---|---|
schemeCategory10 | 10 | Default D3 colors, balanced visibility |
schemeObservable10 | 10 | Modern, web-optimized colors |
schemeTableau10 | 10 | Professional business colors |
schemeAccent | 8 | Bright highlighting colors |
schemeDark2 | 8 | Dark colors for light backgrounds |
schemePastel2 | 8 | Soft, subtle colors |
schemeSet2 | 8 | Medium saturation, balanced |
schemePastel1 | 9 | Light, gentle colors |
schemeSet1 | 9 | Bright, highly saturated |
schemePaired | 12 | Paired light/dark variants |
schemeSet3 | 12 | Light, desaturated colors |