Chart Colors
Change the colors a chart draws its marks in, or pin a chart to light or dark. Charts take your theme's colors and follow the app's appearance with nothing to set up. This page is for when you change a theme color, or keep one chart light or dark.
Installation
provideChartTheme() comes with the chart:
Usage
If you change a color in default.css or dark.css, change it in chart-theme.ts too, or override it in your app config. Pass only the tokens you changed:
Lynx draws the marks with its native <svg> element, which never sees your CSS. And Lynx can't read a variable's value from JavaScript.
So chart-theme.ts keeps a copy of the theme colors, and the chart swaps each var(--token) for its value before drawing. Labels and the tooltip are native views, so they read the CSS variables directly.
Color scheme
Charts follow the app's appearance, as the theme and the icons do. The color scheme says which color table the marks use:
'system'(the default): the appearance the app is drawn in. Use it unless one of the others fits.'light': always light, for a chart on a surface that stays light.'dark': always dark, for a chart on a surface that stays dark.- A function returning
'light'or'dark': for an app that switches a theme class of its own. Read the same signal that sets it.
Set it for every chart with provideChartTheme({ colorScheme: … }). Or set it for one chart, preset or <ui-chart>, with its colorScheme input:
API
provideChartTheme
provideChartTheme(theme) returns a provider for every chart in its injector. Every field is optional, and light, dark and chart merge over their defaults.
- Keep paints as
var(--token)strings, so one definition serves both color schemes. - An unknown token falls back to the
var()'s fallback, as invar(--brand, #2563eb), or to the foreground color.
