Skip to content
OpenChart

Dark mode

How charts switch to dark: the darkMode setting, light and dark color pairs, and preset dark palettes.

Use the theme switch in the site header: every chart on this site redraws in its dark palette, including this one, which sets no dark colors of its own.

05001,0001,500Population (millions)IndiaChinaUnited StatesIndonesiaPakistanNigeriaBrazilBangladeshRussiaEthiopia1,4631,410347285255240217175144135India and China each have more than four timesas many people as the United StatesPopulation of the ten most populous countries, 2025 projection05001,0001,500Population (millions)IndiaChinaUnited StatesIndonesiaPakistanNigeriaBrazilBangladeshRussiaEthiopia1,4631,410347285255240217175144135India and China each have more than four timesas many people as the United StatesPopulation of the ten most populous countries, 2025 projection
Population of the ten most populous countries. Source: UN Population Division, World Population Prospects 2024.
{
  "mark": "bar",
  "data": [
    {
      "country": "India",
      "millions": 1463
    },
    {
      "country": "China",
      "millions": 1410
    },
    {
      "country": "United States",
      "millions": 347
    },
    {
      "country": "Indonesia",
      "millions": 285
    },
    {
      "country": "Pakistan",
      "millions": 255
    },
    {
      "country": "Nigeria",
      "millions": 240
    },
    {
      "country": "Brazil",
      "millions": 217
    },
    {
      "country": "Bangladesh",
      "millions": 175
    },
    {
      "country": "Russia",
      "millions": 144
    },
    {
      "country": "Ethiopia",
      "millions": 135
    }
  ],
  "encoding": {
    "x": {
      "field": "millions",
      "type": "quantitative",
      "axis": {
        "title": "Population (millions)",
        "format": ",.0f"
      }
    },
    "y": {
      "field": "country",
      "type": "nominal",
      "sort": "-x"
    }
  },
  "labels": {
    "format": ",.0f"
  },
  "chrome": {
    "title": "India and China each have more than four times as many people as the United States",
    "subtitle": "Population of the ten most populous countries, 2025 projection"
  }
}
import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 10 rows, as in the Spec tab; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "bar",
  "encoding": {
    "x": {
      "field": "millions",
      "type": "quantitative",
      "axis": {
        "title": "Population (millions)",
        "format": ",.0f"
      }
    },
    "y": {
      "field": "country",
      "type": "nominal",
      "sort": "-x"
    }
  },
  "labels": {
    "format": ",.0f"
  },
  "chrome": {
    "title": "India and China each have more than four times as many people as the United States",
    "subtitle": "Population of the ten most populous countries, 2025 projection"
  }
};

export function Example() {
  return <Chart spec={spec} />;
}
<script setup lang="ts">
import { Chart } from "@opendata-ai/openchart-vue";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 10 rows, as in the Spec tab; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "bar",
  "encoding": {
    "x": {
      "field": "millions",
      "type": "quantitative",
      "axis": {
        "title": "Population (millions)",
        "format": ",.0f"
      }
    },
    "y": {
      "field": "country",
      "type": "nominal",
      "sort": "-x"
    }
  },
  "labels": {
    "format": ",.0f"
  },
  "chrome": {
    "title": "India and China each have more than four times as many people as the United States",
    "subtitle": "Population of the ten most populous countries, 2025 projection"
  }
};
</script>

<template>
  <Chart :spec="spec" />
</template>
<script lang="ts">
import { Chart } from "@opendata-ai/openchart-svelte";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 10 rows, as in the Spec tab; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "bar",
  "encoding": {
    "x": {
      "field": "millions",
      "type": "quantitative",
      "axis": {
        "title": "Population (millions)",
        "format": ",.0f"
      }
    },
    "y": {
      "field": "country",
      "type": "nominal",
      "sort": "-x"
    }
  },
  "labels": {
    "format": ",.0f"
  },
  "chrome": {
    "title": "India and China each have more than four times as many people as the United States",
    "subtitle": "Population of the ten most populous countries, 2025 projection"
  }
};
</script>

<Chart {spec} />
import { createChart } from "@opendata-ai/openchart-vanilla";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 10 rows, as in the Spec tab; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "bar",
  "encoding": {
    "x": {
      "field": "millions",
      "type": "quantitative",
      "axis": {
        "title": "Population (millions)",
        "format": ",.0f"
      }
    },
    "y": {
      "field": "country",
      "type": "nominal",
      "sort": "-x"
    }
  },
  "labels": {
    "format": ",.0f"
  },
  "chrome": {
    "title": "India and China each have more than four times as many people as the United States",
    "subtitle": "Population of the ten most populous countries, 2025 projection"
  }
};

const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);

The darkMode setting

Dark mode is a host setting, not a spec field, because the page decides whether it is dark. Pass darkMode where the chart mounts:

chart.ts
createChart(container, spec, { darkMode: "force" });

React, Vue and Svelte take the same value as a darkMode prop on <Chart>, or once for every chart on <VizThemeProvider>.

Value Behavior
"off" Always light. The default.
"force" Always dark.
"auto" Follows the reader’s system setting through the prefers-color-scheme media query.

"auto" does not see a site’s own theme switch, such as a dark class on the page. If your site has a switch, pass "force" or "off" from its state. This site does that, and remounts each chart when the reader changes theme.

Without dark colors in the theme, the library derives them: it swaps the background and text colors, adjusts the brightness of the palette and lightens the gridlines.

A preset’s dark palette

05001,0001,500Population (millions)IndiaChinaUnited StatesIndonesiaPakistanNigeriaBrazilBangladeshRussiaEthiopia1,4631,410347285255240217175144135India and China each have more than four times asmany people as the United StatesPopulation of the ten most populous countries, 2025 projection05001,0001,500Population (millions)IndiaChinaUnited StatesIndonesiaPakistanNigeriaBrazilBangladeshRussiaEthiopia1,4631,410347285255240217175144135India and China each have more than four times asmany people as the United StatesPopulation of the ten most populous countries, 2025 projection
Population in the broadsheet preset. Source: UN Population Division, World Population Prospects 2024.
{
  "mark": "bar",
  "data": [
    {
      "country": "India",
      "millions": 1463
    },
    {
      "country": "China",
      "millions": 1410
    },
    {
      "country": "United States",
      "millions": 347
    },
    {
      "country": "Indonesia",
      "millions": 285
    },
    {
      "country": "Pakistan",
      "millions": 255
    },
    {
      "country": "Nigeria",
      "millions": 240
    },
    {
      "country": "Brazil",
      "millions": 217
    },
    {
      "country": "Bangladesh",
      "millions": 175
    },
    {
      "country": "Russia",
      "millions": 144
    },
    {
      "country": "Ethiopia",
      "millions": 135
    }
  ],
  "encoding": {
    "x": {
      "field": "millions",
      "type": "quantitative",
      "axis": {
        "title": "Population (millions)",
        "format": ",.0f"
      }
    },
    "y": {
      "field": "country",
      "type": "nominal",
      "sort": "-x"
    }
  },
  "labels": {
    "format": ",.0f"
  },
  "chrome": {
    "title": "India and China each have more than four times as many people as the United States",
    "subtitle": "Population of the ten most populous countries, 2025 projection"
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#1d5f8a",
          "dark": "#5e9fd6"
        },
        {
          "light": "#e3120b",
          "dark": "#f4655a"
        },
        {
          "light": "#7fb0d3",
          "dark": "#93c2e2"
        },
        {
          "light": "#e0a63b",
          "dark": "#e0b267"
        },
        {
          "light": "#3a8a6e",
          "dark": "#4fb093"
        },
        {
          "light": "#8c8680",
          "dark": "#9aa1a8"
        }
      ],
      "categoricalFill": [
        {
          "light": "#3b7097",
          "dark": "#80b5e3"
        },
        {
          "light": "#ee493a",
          "dark": "#ec5b50"
        },
        {
          "light": "#97c2e2",
          "dark": "#acd3eb"
        },
        {
          "light": "#efbb64",
          "dark": "#c6ad55"
        },
        {
          "light": "#579a81",
          "dark": "#5bd2ac"
        },
        {
          "light": "#9e9893",
          "dark": "#b4b9bf"
        }
      ],
      "background": {
        "light": "#fffdf9",
        "dark": "#12181f"
      },
      "text": {
        "light": "#1a1714",
        "dark": "#e9ebe6"
      },
      "gridline": {
        "light": "rgba(26,23,20,0.08)",
        "dark": "rgba(233,235,230,0.07)"
      },
      "hairline": {
        "light": "rgba(26,23,20,0.28)",
        "dark": "rgba(233,235,230,0.28)"
      },
      "axis": {
        "light": "#6b645c",
        "dark": "#9aa4ad"
      },
      "annotationFill": {
        "light": "rgba(26,23,20,0.05)",
        "dark": "rgba(233,235,230,0.07)"
      },
      "annotationText": {
        "light": "#6b645c",
        "dark": "#9aa4ad"
      }
    },
    "fonts": {
      "sizes": {
        "title": 24,
        "subtitle": 14,
        "body": 13,
        "small": 11
      }
    },
    "spacing": {
      "padding": 20,
      "chromeGap": 8,
      "chromeToChart": 16,
      "chartToFooter": 12
    },
    "chrome": {
      "eyebrow": {
        "color": {
          "light": "#e3120b",
          "dark": "#f4463f"
        },
        "fontSize": 11,
        "fontWeight": 700
      },
      "title": {
        "fontWeight": 700,
        "lineHeight": 1.18
      },
      "subtitle": {
        "fontWeight": 400,
        "lineHeight": 1.45
      }
    },
    "rule": {
      "color": {
        "light": "#e3120b",
        "dark": "#f4463f"
      },
      "width": 40,
      "thickness": 3
    },
    "borderRadius": 0
  }
}
import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 10 rows, as in the Spec tab; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "bar",
  "encoding": {
    "x": {
      "field": "millions",
      "type": "quantitative",
      "axis": {
        "title": "Population (millions)",
        "format": ",.0f"
      }
    },
    "y": {
      "field": "country",
      "type": "nominal",
      "sort": "-x"
    }
  },
  "labels": {
    "format": ",.0f"
  },
  "chrome": {
    "title": "India and China each have more than four times as many people as the United States",
    "subtitle": "Population of the ten most populous countries, 2025 projection"
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#1d5f8a",
          "dark": "#5e9fd6"
        },
        {
          "light": "#e3120b",
          "dark": "#f4655a"
        },
        {
          "light": "#7fb0d3",
          "dark": "#93c2e2"
        },
        {
          "light": "#e0a63b",
          "dark": "#e0b267"
        },
        {
          "light": "#3a8a6e",
          "dark": "#4fb093"
        },
        {
          "light": "#8c8680",
          "dark": "#9aa1a8"
        }
      ],
      "categoricalFill": [
        {
          "light": "#3b7097",
          "dark": "#80b5e3"
        },
        {
          "light": "#ee493a",
          "dark": "#ec5b50"
        },
        {
          "light": "#97c2e2",
          "dark": "#acd3eb"
        },
        {
          "light": "#efbb64",
          "dark": "#c6ad55"
        },
        {
          "light": "#579a81",
          "dark": "#5bd2ac"
        },
        {
          "light": "#9e9893",
          "dark": "#b4b9bf"
        }
      ],
      "background": {
        "light": "#fffdf9",
        "dark": "#12181f"
      },
      "text": {
        "light": "#1a1714",
        "dark": "#e9ebe6"
      },
      "gridline": {
        "light": "rgba(26,23,20,0.08)",
        "dark": "rgba(233,235,230,0.07)"
      },
      "hairline": {
        "light": "rgba(26,23,20,0.28)",
        "dark": "rgba(233,235,230,0.28)"
      },
      "axis": {
        "light": "#6b645c",
        "dark": "#9aa4ad"
      },
      "annotationFill": {
        "light": "rgba(26,23,20,0.05)",
        "dark": "rgba(233,235,230,0.07)"
      },
      "annotationText": {
        "light": "#6b645c",
        "dark": "#9aa4ad"
      }
    },
    "fonts": {
      "sizes": {
        "title": 24,
        "subtitle": 14,
        "body": 13,
        "small": 11
      }
    },
    "spacing": {
      "padding": 20,
      "chromeGap": 8,
      "chromeToChart": 16,
      "chartToFooter": 12
    },
    "chrome": {
      "eyebrow": {
        "color": {
          "light": "#e3120b",
          "dark": "#f4463f"
        },
        "fontSize": 11,
        "fontWeight": 700
      },
      "title": {
        "fontWeight": 700,
        "lineHeight": 1.18
      },
      "subtitle": {
        "fontWeight": 400,
        "lineHeight": 1.45
      }
    },
    "rule": {
      "color": {
        "light": "#e3120b",
        "dark": "#f4463f"
      },
      "width": 40,
      "thickness": 3
    },
    "borderRadius": 0
  }
};

export function Example() {
  return <Chart spec={spec} />;
}
<script setup lang="ts">
import { Chart } from "@opendata-ai/openchart-vue";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 10 rows, as in the Spec tab; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "bar",
  "encoding": {
    "x": {
      "field": "millions",
      "type": "quantitative",
      "axis": {
        "title": "Population (millions)",
        "format": ",.0f"
      }
    },
    "y": {
      "field": "country",
      "type": "nominal",
      "sort": "-x"
    }
  },
  "labels": {
    "format": ",.0f"
  },
  "chrome": {
    "title": "India and China each have more than four times as many people as the United States",
    "subtitle": "Population of the ten most populous countries, 2025 projection"
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#1d5f8a",
          "dark": "#5e9fd6"
        },
        {
          "light": "#e3120b",
          "dark": "#f4655a"
        },
        {
          "light": "#7fb0d3",
          "dark": "#93c2e2"
        },
        {
          "light": "#e0a63b",
          "dark": "#e0b267"
        },
        {
          "light": "#3a8a6e",
          "dark": "#4fb093"
        },
        {
          "light": "#8c8680",
          "dark": "#9aa1a8"
        }
      ],
      "categoricalFill": [
        {
          "light": "#3b7097",
          "dark": "#80b5e3"
        },
        {
          "light": "#ee493a",
          "dark": "#ec5b50"
        },
        {
          "light": "#97c2e2",
          "dark": "#acd3eb"
        },
        {
          "light": "#efbb64",
          "dark": "#c6ad55"
        },
        {
          "light": "#579a81",
          "dark": "#5bd2ac"
        },
        {
          "light": "#9e9893",
          "dark": "#b4b9bf"
        }
      ],
      "background": {
        "light": "#fffdf9",
        "dark": "#12181f"
      },
      "text": {
        "light": "#1a1714",
        "dark": "#e9ebe6"
      },
      "gridline": {
        "light": "rgba(26,23,20,0.08)",
        "dark": "rgba(233,235,230,0.07)"
      },
      "hairline": {
        "light": "rgba(26,23,20,0.28)",
        "dark": "rgba(233,235,230,0.28)"
      },
      "axis": {
        "light": "#6b645c",
        "dark": "#9aa4ad"
      },
      "annotationFill": {
        "light": "rgba(26,23,20,0.05)",
        "dark": "rgba(233,235,230,0.07)"
      },
      "annotationText": {
        "light": "#6b645c",
        "dark": "#9aa4ad"
      }
    },
    "fonts": {
      "sizes": {
        "title": 24,
        "subtitle": 14,
        "body": 13,
        "small": 11
      }
    },
    "spacing": {
      "padding": 20,
      "chromeGap": 8,
      "chromeToChart": 16,
      "chartToFooter": 12
    },
    "chrome": {
      "eyebrow": {
        "color": {
          "light": "#e3120b",
          "dark": "#f4463f"
        },
        "fontSize": 11,
        "fontWeight": 700
      },
      "title": {
        "fontWeight": 700,
        "lineHeight": 1.18
      },
      "subtitle": {
        "fontWeight": 400,
        "lineHeight": 1.45
      }
    },
    "rule": {
      "color": {
        "light": "#e3120b",
        "dark": "#f4463f"
      },
      "width": 40,
      "thickness": 3
    },
    "borderRadius": 0
  }
};
</script>

<template>
  <Chart :spec="spec" />
</template>
<script lang="ts">
import { Chart } from "@opendata-ai/openchart-svelte";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 10 rows, as in the Spec tab; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "bar",
  "encoding": {
    "x": {
      "field": "millions",
      "type": "quantitative",
      "axis": {
        "title": "Population (millions)",
        "format": ",.0f"
      }
    },
    "y": {
      "field": "country",
      "type": "nominal",
      "sort": "-x"
    }
  },
  "labels": {
    "format": ",.0f"
  },
  "chrome": {
    "title": "India and China each have more than four times as many people as the United States",
    "subtitle": "Population of the ten most populous countries, 2025 projection"
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#1d5f8a",
          "dark": "#5e9fd6"
        },
        {
          "light": "#e3120b",
          "dark": "#f4655a"
        },
        {
          "light": "#7fb0d3",
          "dark": "#93c2e2"
        },
        {
          "light": "#e0a63b",
          "dark": "#e0b267"
        },
        {
          "light": "#3a8a6e",
          "dark": "#4fb093"
        },
        {
          "light": "#8c8680",
          "dark": "#9aa1a8"
        }
      ],
      "categoricalFill": [
        {
          "light": "#3b7097",
          "dark": "#80b5e3"
        },
        {
          "light": "#ee493a",
          "dark": "#ec5b50"
        },
        {
          "light": "#97c2e2",
          "dark": "#acd3eb"
        },
        {
          "light": "#efbb64",
          "dark": "#c6ad55"
        },
        {
          "light": "#579a81",
          "dark": "#5bd2ac"
        },
        {
          "light": "#9e9893",
          "dark": "#b4b9bf"
        }
      ],
      "background": {
        "light": "#fffdf9",
        "dark": "#12181f"
      },
      "text": {
        "light": "#1a1714",
        "dark": "#e9ebe6"
      },
      "gridline": {
        "light": "rgba(26,23,20,0.08)",
        "dark": "rgba(233,235,230,0.07)"
      },
      "hairline": {
        "light": "rgba(26,23,20,0.28)",
        "dark": "rgba(233,235,230,0.28)"
      },
      "axis": {
        "light": "#6b645c",
        "dark": "#9aa4ad"
      },
      "annotationFill": {
        "light": "rgba(26,23,20,0.05)",
        "dark": "rgba(233,235,230,0.07)"
      },
      "annotationText": {
        "light": "#6b645c",
        "dark": "#9aa4ad"
      }
    },
    "fonts": {
      "sizes": {
        "title": 24,
        "subtitle": 14,
        "body": 13,
        "small": 11
      }
    },
    "spacing": {
      "padding": 20,
      "chromeGap": 8,
      "chromeToChart": 16,
      "chartToFooter": 12
    },
    "chrome": {
      "eyebrow": {
        "color": {
          "light": "#e3120b",
          "dark": "#f4463f"
        },
        "fontSize": 11,
        "fontWeight": 700
      },
      "title": {
        "fontWeight": 700,
        "lineHeight": 1.18
      },
      "subtitle": {
        "fontWeight": 400,
        "lineHeight": 1.45
      }
    },
    "rule": {
      "color": {
        "light": "#e3120b",
        "dark": "#f4463f"
      },
      "width": 40,
      "thickness": 3
    },
    "borderRadius": 0
  }
};
</script>

<Chart {spec} />
import { createChart } from "@opendata-ai/openchart-vanilla";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 10 rows, as in the Spec tab; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "bar",
  "encoding": {
    "x": {
      "field": "millions",
      "type": "quantitative",
      "axis": {
        "title": "Population (millions)",
        "format": ",.0f"
      }
    },
    "y": {
      "field": "country",
      "type": "nominal",
      "sort": "-x"
    }
  },
  "labels": {
    "format": ",.0f"
  },
  "chrome": {
    "title": "India and China each have more than four times as many people as the United States",
    "subtitle": "Population of the ten most populous countries, 2025 projection"
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#1d5f8a",
          "dark": "#5e9fd6"
        },
        {
          "light": "#e3120b",
          "dark": "#f4655a"
        },
        {
          "light": "#7fb0d3",
          "dark": "#93c2e2"
        },
        {
          "light": "#e0a63b",
          "dark": "#e0b267"
        },
        {
          "light": "#3a8a6e",
          "dark": "#4fb093"
        },
        {
          "light": "#8c8680",
          "dark": "#9aa1a8"
        }
      ],
      "categoricalFill": [
        {
          "light": "#3b7097",
          "dark": "#80b5e3"
        },
        {
          "light": "#ee493a",
          "dark": "#ec5b50"
        },
        {
          "light": "#97c2e2",
          "dark": "#acd3eb"
        },
        {
          "light": "#efbb64",
          "dark": "#c6ad55"
        },
        {
          "light": "#579a81",
          "dark": "#5bd2ac"
        },
        {
          "light": "#9e9893",
          "dark": "#b4b9bf"
        }
      ],
      "background": {
        "light": "#fffdf9",
        "dark": "#12181f"
      },
      "text": {
        "light": "#1a1714",
        "dark": "#e9ebe6"
      },
      "gridline": {
        "light": "rgba(26,23,20,0.08)",
        "dark": "rgba(233,235,230,0.07)"
      },
      "hairline": {
        "light": "rgba(26,23,20,0.28)",
        "dark": "rgba(233,235,230,0.28)"
      },
      "axis": {
        "light": "#6b645c",
        "dark": "#9aa4ad"
      },
      "annotationFill": {
        "light": "rgba(26,23,20,0.05)",
        "dark": "rgba(233,235,230,0.07)"
      },
      "annotationText": {
        "light": "#6b645c",
        "dark": "#9aa4ad"
      }
    },
    "fonts": {
      "sizes": {
        "title": 24,
        "subtitle": 14,
        "body": 13,
        "small": 11
      }
    },
    "spacing": {
      "padding": 20,
      "chromeGap": 8,
      "chromeToChart": 16,
      "chartToFooter": 12
    },
    "chrome": {
      "eyebrow": {
        "color": {
          "light": "#e3120b",
          "dark": "#f4463f"
        },
        "fontSize": 11,
        "fontWeight": 700
      },
      "title": {
        "fontWeight": 700,
        "lineHeight": 1.18
      },
      "subtitle": {
        "fontWeight": 400,
        "lineHeight": 1.45
      }
    },
    "rule": {
      "color": {
        "light": "#e3120b",
        "dark": "#f4463f"
      },
      "width": 40,
      "thickness": 3
    },
    "borderRadius": 0
  }
};

const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);

Presets carry their own dark colors. Broadsheet’s warm paper turns to an ink-blue night page, its text to a cool off-white, and its palette lifts to hold the same contrast: the red rule goes a shade lighter with it. Terminal is the exception: it is dark in both modes.

Light and dark color pairs

1900192019401960198020002020Year−0.5+0.0+0.5+1.0Difference from the 1951–1980 average (°C)CoolerWarmerGlobal temperature has been above the1951–1980 average in every reading since 1970Global surface temperature, difference from the 1951–1980 average (°C), by decade from1900, plus 20251900192019401960198020002020Year−0.5+0.0+0.5+1.0Difference from the 1951–1980 average (°C)CoolerWarmerGlobal temperature has been above the1951–1980 average in every reading since 1970Global surface temperature, difference from the 1951–1980 average (°C), by decade from1900, plus 2025
Global temperature anomaly in a theme of color pairs. Source: NASA GISS Surface Temperature Analysis (GISTEMP v4).
{
  "mark": "bar",
  "data": [
    {
      "year": "1900",
      "anomaly": -0.08,
      "trend": "Cooler"
    },
    {
      "year": "1910",
      "anomaly": -0.43,
      "trend": "Cooler"
    },
    {
      "year": "1920",
      "anomaly": -0.27,
      "trend": "Cooler"
    },
    {
      "year": "1930",
      "anomaly": -0.16,
      "trend": "Cooler"
    },
    {
      "year": "1940",
      "anomaly": 0.12,
      "trend": "Warmer"
    },
    {
      "year": "1950",
      "anomaly": -0.17,
      "trend": "Cooler"
    },
    // … 8 more rows; Copy includes them
  ],
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "title": "Year",
        "format": "%Y"
      }
    },
    "y": {
      "field": "anomaly",
      "type": "quantitative",
      "axis": {
        "title": "Difference from the 1951–1980 average (°C)",
        "format": "+.1f"
      }
    },
    "color": {
      "field": "trend",
      "type": "nominal",
      "scale": {
        "domain": [
          "Cooler",
          "Warmer"
        ]
      }
    }
  },
  "labels": {
    "density": "none"
  },
  "annotations": [
    {
      "type": "refline",
      "y": 0,
      "style": "solid",
      "strokeWidth": 1
    }
  ],
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#1d5f8a",
          "dark": "#7fb0d3"
        },
        {
          "light": "#c2410c",
          "dark": "#fb923c"
        }
      ],
      "background": {
        "light": "#fff8ef",
        "dark": "#17130f"
      },
      "text": {
        "light": "#2b2118",
        "dark": "#f3e9dc"
      },
      "axis": {
        "light": "#76695b",
        "dark": "#b3a493"
      }
    }
  },
  "chrome": {
    "title": "Global temperature has been above the 1951–1980 average in every reading since 1970",
    "subtitle": "Global surface temperature, difference from the 1951–1980 average (°C), by decade from 1900, plus 2025"
  }
}
import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 14 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "bar",
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "title": "Year",
        "format": "%Y"
      }
    },
    "y": {
      "field": "anomaly",
      "type": "quantitative",
      "axis": {
        "title": "Difference from the 1951–1980 average (°C)",
        "format": "+.1f"
      }
    },
    "color": {
      "field": "trend",
      "type": "nominal",
      "scale": {
        "domain": [
          "Cooler",
          "Warmer"
        ]
      }
    }
  },
  "labels": {
    "density": "none"
  },
  "annotations": [
    {
      "type": "refline",
      "y": 0,
      "style": "solid",
      "strokeWidth": 1
    }
  ],
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#1d5f8a",
          "dark": "#7fb0d3"
        },
        {
          "light": "#c2410c",
          "dark": "#fb923c"
        }
      ],
      "background": {
        "light": "#fff8ef",
        "dark": "#17130f"
      },
      "text": {
        "light": "#2b2118",
        "dark": "#f3e9dc"
      },
      "axis": {
        "light": "#76695b",
        "dark": "#b3a493"
      }
    }
  },
  "chrome": {
    "title": "Global temperature has been above the 1951–1980 average in every reading since 1970",
    "subtitle": "Global surface temperature, difference from the 1951–1980 average (°C), by decade from 1900, plus 2025"
  }
};

export function Example() {
  return <Chart spec={spec} />;
}
<script setup lang="ts">
import { Chart } from "@opendata-ai/openchart-vue";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 14 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "bar",
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "title": "Year",
        "format": "%Y"
      }
    },
    "y": {
      "field": "anomaly",
      "type": "quantitative",
      "axis": {
        "title": "Difference from the 1951–1980 average (°C)",
        "format": "+.1f"
      }
    },
    "color": {
      "field": "trend",
      "type": "nominal",
      "scale": {
        "domain": [
          "Cooler",
          "Warmer"
        ]
      }
    }
  },
  "labels": {
    "density": "none"
  },
  "annotations": [
    {
      "type": "refline",
      "y": 0,
      "style": "solid",
      "strokeWidth": 1
    }
  ],
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#1d5f8a",
          "dark": "#7fb0d3"
        },
        {
          "light": "#c2410c",
          "dark": "#fb923c"
        }
      ],
      "background": {
        "light": "#fff8ef",
        "dark": "#17130f"
      },
      "text": {
        "light": "#2b2118",
        "dark": "#f3e9dc"
      },
      "axis": {
        "light": "#76695b",
        "dark": "#b3a493"
      }
    }
  },
  "chrome": {
    "title": "Global temperature has been above the 1951–1980 average in every reading since 1970",
    "subtitle": "Global surface temperature, difference from the 1951–1980 average (°C), by decade from 1900, plus 2025"
  }
};
</script>

<template>
  <Chart :spec="spec" />
</template>
<script lang="ts">
import { Chart } from "@opendata-ai/openchart-svelte";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 14 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "bar",
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "title": "Year",
        "format": "%Y"
      }
    },
    "y": {
      "field": "anomaly",
      "type": "quantitative",
      "axis": {
        "title": "Difference from the 1951–1980 average (°C)",
        "format": "+.1f"
      }
    },
    "color": {
      "field": "trend",
      "type": "nominal",
      "scale": {
        "domain": [
          "Cooler",
          "Warmer"
        ]
      }
    }
  },
  "labels": {
    "density": "none"
  },
  "annotations": [
    {
      "type": "refline",
      "y": 0,
      "style": "solid",
      "strokeWidth": 1
    }
  ],
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#1d5f8a",
          "dark": "#7fb0d3"
        },
        {
          "light": "#c2410c",
          "dark": "#fb923c"
        }
      ],
      "background": {
        "light": "#fff8ef",
        "dark": "#17130f"
      },
      "text": {
        "light": "#2b2118",
        "dark": "#f3e9dc"
      },
      "axis": {
        "light": "#76695b",
        "dark": "#b3a493"
      }
    }
  },
  "chrome": {
    "title": "Global temperature has been above the 1951–1980 average in every reading since 1970",
    "subtitle": "Global surface temperature, difference from the 1951–1980 average (°C), by decade from 1900, plus 2025"
  }
};
</script>

<Chart {spec} />
import { createChart } from "@opendata-ai/openchart-vanilla";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 14 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "bar",
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "title": "Year",
        "format": "%Y"
      }
    },
    "y": {
      "field": "anomaly",
      "type": "quantitative",
      "axis": {
        "title": "Difference from the 1951–1980 average (°C)",
        "format": "+.1f"
      }
    },
    "color": {
      "field": "trend",
      "type": "nominal",
      "scale": {
        "domain": [
          "Cooler",
          "Warmer"
        ]
      }
    }
  },
  "labels": {
    "density": "none"
  },
  "annotations": [
    {
      "type": "refline",
      "y": 0,
      "style": "solid",
      "strokeWidth": 1
    }
  ],
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#1d5f8a",
          "dark": "#7fb0d3"
        },
        {
          "light": "#c2410c",
          "dark": "#fb923c"
        }
      ],
      "background": {
        "light": "#fff8ef",
        "dark": "#17130f"
      },
      "text": {
        "light": "#2b2118",
        "dark": "#f3e9dc"
      },
      "axis": {
        "light": "#76695b",
        "dark": "#b3a493"
      }
    }
  },
  "chrome": {
    "title": "Global temperature has been above the 1951–1980 average in every reading since 1970",
    "subtitle": "Global surface temperature, difference from the 1951–1980 average (°C), by decade from 1900, plus 2025"
  }
};

const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);

Any single color in a theme can be a { light, dark } pair. The library then uses your dark value instead of deriving one, which is how you keep brand colors exact in both modes. This chart sets pairs for the background, the text, the axis and both series colors:

theme.ts
const theme = {
  colors: {
    categorical: [
      { light: "#1d5f8a", dark: "#7fb0d3" },
      { light: "#c2410c", dark: "#fb923c" },
    ],
    background: { light: "#fff8ef", dark: "#17130f" },
    text: { light: "#2b2118", dark: "#f3e9dc" },
    axis: { light: "#76695b", dark: "#b3a493" },
  },
};

Pairs replace whole when themes merge, so a later theme layer that sets background replaces both of its values.

Fields that matter

Field What it does
darkMode (mount option or prop) "off", "force" or "auto".
theme.colors.* as { light, dark } Sets the dark value of one color yourself.
theme.colors.categorical A list of colors or pairs, one per series.