Birch UI Charts overviewCharts
Fast, accessible canvas charts for line, area, bar, column, scatter, bubble, pie, donut, heatmap and combination charts, with SVG and PNG export and grid integration.
Birch UI Charts draws fast, accessible charts on a canvas: line, area, column and bar, scatter and bubble, pie and donut, heatmaps, combination charts with a secondary axis, and sparklines for grid cells. Every chart exports to SVG and PNG, lines with a million points render in a fraction of a second, and a range selected in Grid Pro can become a chart in one call.
It is written in plain TypeScript and follows the same widget contract as every Birch UI component, so it works in any framework.
Loading demo…
View source
Sample data and small UI helpers are imported from the docs' demos/_shared.ts and demos/_scheduler-data.ts files.
import { createChart } from '@birchui/charts';
import { button, docsTheme, layout, onDocsThemeChange, seededRandom } from './_shared';
export const meta = { title: 'One million telemetry points', height: 460 };
interface Reading {
time: number;
temperature: number;
}
const POINT_COUNT = 1_000_000;
const START = Date.UTC(2026, 9, 1);
const INTERVAL_MS = 2_000;
function makeReadings(): Reading[] {
const random = seededRandom(17);
const readings: Reading[] = new Array(POINT_COUNT);
let value = 21;
for (let i = 0; i < POINT_COUNT; i++) {
const daily = Math.sin((i / 43_200) * Math.PI * 2) * 2.5;
value += (random() - 0.5) * 0.08 - (value - 21) * 0.0005;
const spike = random() < 0.00002 ? 6 + random() * 4 : 0;
readings[i] = { time: START + i * INTERVAL_MS, temperature: Math.round((value + daily + spike) * 100) / 100 };
}
return readings;
}
export default function mount(el: HTMLElement): () => void {
const { toolbar, body, status } = layout(el);
const generated = performance.now();
const data = makeReadings();
const started = performance.now();
const chart = createChart<Reading>(body, {
title: 'Cold storage unit 4: temperature',
subtitle: `${POINT_COUNT.toLocaleString()} readings, one every 2 seconds`,
data,
series: [{ type: 'line', xKey: 'time', yKey: 'temperature', name: 'Temperature (°C)', decimation: true }],
axes: { x: { type: 'time' }, y: { title: '°C' } },
zoom: true,
legend: false,
theme: docsTheme(),
height: '100%',
});
const rendered = Math.round(performance.now() - started);
status.textContent = `Generated in ${Math.round(started - generated)} ms, first render in ${rendered} ms. Drag across the plot to zoom.`;
toolbar.append(
button('Zoom to first day', () => chart.setZoom([START, START + 86_400_000])),
button('Reset zoom', () => chart.resetZoom()),
button('Download PNG', () => {
chart.download('png', 'cold-storage-unit-4').catch((error: Error) => {
status.textContent = `Export failed: ${error.message}`;
});
}),
);
const offZoom = chart.on('zoomChange', ({ range, source }) => {
status.textContent = range
? `Showing ${new Date(range[0]).toISOString().slice(0, 16)} to ${new Date(range[1]).toISOString().slice(0, 16)} UTC (${source})`
: 'Showing the full range.';
});
const stopTheme = onDocsThemeChange((theme) => chart.update({ theme }));
return () => {
offZoom();
stopTheme();
chart.destroy();
};
}Install#
npm install @birchui/core @birchui/charts@birchui/core provides the shared widget contract and style helpers; @birchui/license comes along as a dependency. The charts package is about 38 KB minified and gzipped, not counting those two.
A first chart#
import { createChart } from '@birchui/charts';
interface MonthlyRevenue {
month: string;
northAmerica: number;
europe: number;
asiaPacific: number;
}
const revenue: MonthlyRevenue[] = [
{ month: 'Jan', northAmerica: 412_000, europe: 288_000, asiaPacific: 196_000 },
{ month: 'Feb', northAmerica: 398_000, europe: 276_000, asiaPacific: 204_000 },
{ month: 'Mar', northAmerica: 455_000, europe: 301_000, asiaPacific: 231_000 },
{ month: 'Apr', northAmerica: 471_000, europe: 319_000, asiaPacific: 244_000 },
];
const usd = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', notation: 'compact' });
const chart = createChart<MonthlyRevenue>(document.querySelector<HTMLElement>('#revenue')!, {
title: 'Monthly revenue by region',
subtitle: 'Fiscal year 2026, USD',
data: revenue,
series: [
{ type: 'column', xKey: 'month', yKey: 'northAmerica', name: 'North America' },
{ type: 'column', xKey: 'month', yKey: 'europe', name: 'Europe' },
{ type: 'column', xKey: 'month', yKey: 'asiaPacific', name: 'Asia Pacific' },
],
axes: { y: { labelFormatter: (value) => usd.format(Number(value)) } },
});
chart.on('pointClick', ({ point }) => console.info(point.seriesName, point.datum.month, point.y));<div id="revenue"></div>The chart fills the width of its container and follows it as it resizes. Its height is 320 pixels by default; set height to a number of pixels or any CSS length. A percentage such as '100%' makes the chart fill a container that has its own height.
xKey and yKey are typed against your datum type, so a misspelled key is a compile error.
The widget contract#
createChart(container, options) returns a ChartApi. Like every Birch UI widget it has:
| Member | Description |
|---|---|
element |
The chart's root element |
update(partial) |
Apply only the options you pass. Data and series changes animate. |
on(event, listener) |
Subscribe to an event; returns an unsubscribe function |
destroy() |
Remove the chart and release every listener, observer and animation frame |
On top of that it adds data, zoom, visibility and export methods. See the API reference.
chart.update({ theme: 'dark', subtitle: 'Fiscal year 2026, USD, updated hourly' });
chart.setData(await fetchRevenue());
chart.setSeries(chart.getOptions().series.map((series) => ({ ...series, stacked: true })));chartDefinition describes the widget for framework adapters and custom elements: its name is BirchChart, its tag name birchui-chart, and its events are ready, pointClick, legendToggle, zoomChange and seriesHover.
createChart() throws a TypeError only for programmer errors: a missing container or a missing options object. Invalid series, unknown series types and bad option values produce one console.warn each and are skipped or replaced with a safe default, and errors thrown in your callbacks (formatters, renderers) are reported with console.error without breaking the chart.
Themes and styles#
theme is 'light', 'dark' or 'auto'. It defaults to 'auto', which follows the user's prefers-color-scheme. The root element gets the class lq-chart-theme-light, lq-chart-theme-dark or lq-chart-theme-auto.
Colors come from CSS custom properties read from the chart's computed style: the shared --lq-* properties (--lq-fg, --lq-bg, --lq-muted-fg, --lq-border, --lq-accent, --lq-font-family, --lq-font-size and others), plus chart-specific ones:
| Property | Used for |
|---|---|
--lq-chart-grid |
Grid lines |
--lq-chart-color-1 … --lq-chart-color-8 |
The categorical series palette |
--lq-chart-heat-1 … --lq-chart-heat-4 |
The sequential heatmap ramp |
--lq-chart-tooltip-shadow |
Tooltip shadow |
Override them in CSS, or pass palette: ['#…', …] to set series colors directly. A series color always wins.
.lq-chart.lq-chart-theme-light {
--lq-chart-color-1: #0a6c9e;
--lq-chart-color-2: #b54708;
}Styles are injected into the document head the first time a chart is created. Set injectStyles: false and import @birchui/charts/styles.css to ship them in your own bundle; the CSS is also exported as the string chartStyles.
Licensing#
Every chart checks for a license when it is created by calling checkLicense('charts', { key, host }) from @birchui/license. The check runs entirely in the browser; no network request is ever made.
- Pass the key with the
licenseKeyoption, or set it once for the whole app withsetLicenseKey(key)from@birchui/license. Charts created without an explicitlicenseKeypick up a key set later, without being recreated. - Without a valid key, every feature keeps working. The chart shows a small "unlicensed copy" watermark and the console shows one warning per page load.
- On localhost and other local development hosts, the watermark is not shown, so you can evaluate and develop without a key.
- Changing
licenseKeythroughupdate()re-runs the check.
import { setLicenseKey } from '@birchui/license';
setLicenseKey(import.meta.env.VITE_BIRCHUI_LICENSE_KEY);See Licensing & activation for key formats, seats and how updates work, and Pricing for every product.
Using charts in a framework#
The framework adapters do not ship a ready-made chart component, and there is no /charts subpath. Each adapter exports the generic factory it uses for its own components. Pass it chartDefinition and you get a component that creates the chart on mount, sends changed props to update() and forwards every chart event.
import { createChart } from '@birchui/charts';
const chart = createChart(document.getElementById('sessions')!, {
title: 'Website sessions',
data: sessions,
series: [{ type: 'line', xKey: 'date', yKey: 'sessions', name: 'Sessions' }],
});
chart.on('pointClick', ({ point }) => openDay(point.datum.date));import { createReactComponent } from '@birchui/react';
import { chartDefinition } from '@birchui/charts';
export const BirchChart = createReactComponent(chartDefinition);
export function SessionsChart({ sessions }: { sessions: DailySessions[] }) {
return (
<BirchChart
title="Website sessions"
data={sessions}
series={[{ type: 'line', xKey: 'date', yKey: 'sessions', name: 'Sessions' }]}
onPointClick={({ point }) => openDay(point.datum.date as string)}
/>
);
}<script setup lang="ts">
import { createVueComponent } from '@birchui/vue';
import { chartDefinition, type ChartEvents } from '@birchui/charts';
const BirchChart = createVueComponent(chartDefinition);
defineProps<{ sessions: DailySessions[] }>();
const series = [{ type: 'line', xKey: 'date', yKey: 'sessions', name: 'Sessions' }];
function onPointClick({ point }: ChartEvents['pointClick']) {
openDay(point.datum.date as string);
}
</script>
<template>
<BirchChart title="Website sessions" :data="sessions" :series="series" @point-click="onPointClick" />
</template>import { ChangeDetectionStrategy, Component, input, output } from '@angular/core';
import { injectBirchWidget, withOverrides, type WidgetOutputs } from '@birchui/angular';
import { chartDefinition, type ChartApi, type ChartEvents, type ChartOptions } from '@birchui/charts';
@Component({
selector: 'app-chart',
standalone: true,
changeDetection: ChangeDetectionStrategy.OnPush,
template: '',
styles: ':host { display: block; }',
})
export class ChartComponent implements WidgetOutputs<ChartEvents> {
readonly options = input<ChartOptions>({ series: [] });
readonly data = input<ChartOptions['data']>();
readonly ready = output<ChartEvents['ready']>();
readonly pointClick = output<ChartEvents['pointClick']>();
readonly legendToggle = output<ChartEvents['legendToggle']>();
readonly zoomChange = output<ChartEvents['zoomChange']>();
readonly seriesHover = output<ChartEvents['seriesHover']>();
private readonly widget = injectBirchWidget(chartDefinition, this, () =>
withOverrides<ChartOptions>(this.options(), { data: this.data() }),
);
get api(): ChartApi | undefined {
return this.widget.instance;
}
}<script lang="ts">
import { createSvelteAction } from '@birchui/svelte';
import { chartDefinition, type ChartApi } from '@birchui/charts';
const birchChart = createSvelteAction(chartDefinition);
let { sessions }: { sessions: DailySessions[] } = $props();
let api: ChartApi | null = $state.raw(null);
</script>
<div
use:birchChart={{
title: 'Website sessions',
data: sessions,
series: [{ type: 'line', xKey: 'date', yKey: 'sessions', name: 'Sessions' }],
on: { pointClick: ({ point }) => openDay(point.datum.date as string) },
onReady: (chart) => (api = chart),
}}
></div>import { createSolidComponent } from '@birchui/solid';
import { chartDefinition } from '@birchui/charts';
export const BirchChart = createSolidComponent(chartDefinition);
export function SessionsChart(props: { sessions: DailySessions[] }) {
return (
<BirchChart
title="Website sessions"
data={props.sessions}
series={[{ type: 'line', xKey: 'date', yKey: 'sessions', name: 'Sessions' }]}
onPointClick={({ point }) => openDay(point.datum.date as string)}
/>
);
}<birchui-chart id="sessions" theme="auto"></birchui-chart>
<script type="module">
import { createElementClass } from '@birchui/element';
import { chartDefinition } from '@birchui/charts';
customElements.define(
'birchui-chart',
createElementClass(chartDefinition, {
optionKeys: ['data', 'series', 'axes', 'tooltip', 'palette', 'subtitle'],
attributes: { theme: 'string', locale: 'string', 'license-key': 'string' },
requiredOptions: ['series'],
}),
);
const chart = document.getElementById('sessions');
chart.set('title', 'Website sessions');
chart.data = sessions;
chart.series = [{ type: 'line', xKey: 'date', yKey: 'sessions', name: 'Sessions' }];
chart.addEventListener('point-click', ({ detail: { point } }) => openDay(point.datum.date));
</script>Notes per adapter:
- React and Solid: options are props, events are
on…props (onPointClick,onZoomChange), andrefgives you theChartApi. - Vue: pass options as attributes (kebab-case is converted to camelCase) or as an
optionsobject. Events are kebab-case (@point-click,@zoom-change). - Angular:
injectBirchWidgetneeds one output per chart event, which is why the wrapper declares all five. Read the instance fromapiafter the first render. - Svelte:
createSvelteActiongives you an action. Its parameter is the options pluson(handlers keyed by event name) andonReady(called once with the API). - Web Component:
createElementClassturns the definition into a custom element.optionKeysbecome properties,attributesare observed and converted to camelCase options, andrequiredOptions: ['series']waits for series before creating the chart. Option names that already exist onHTMLElement, such astitle, do not become properties; set them withelement.set('title', …). Events are kebab-caseCustomEvents with the payload indetail, andelement.apiis theChartApi. Define the element in the browser only; the class needs a DOM.
Next steps#
- Series: every chart type and its options.
- Axes: category, linear, log and time axes, and secondary axes.
- Interaction: tooltips, legend, zoom and pan.
- Large data: a million points in a line chart.
- Grid integration: charts from Grid Pro ranges and sparklines in cells.