Skip to content

Chart

<ax-chart> is a dependency-free SVG chart built on a pure chart-core. It supports line, area, bar, scatter, pie, and donut types, optional stacking, custom formatters, keyboard exploration, and pointer events. Responsive via viewBox, themed through --color-chart-1..5, and self-gates with a PRO watermark until licensed.

import {
AxChartComponent,
formatChartValue,
formatChartLabel,
formatPercent,
type ChartSeriesInput,
type ChartValueFormatter,
type ChartLabelFormatter,
type ChartPointEvent,
type ChartType,
} from '@axisui-ng/charts';
<ax-chart
type="line"
[series]="[
{ name: 'Revenue', data: [84200, 92100, 88500, 95400, 102300] },
{ name: 'Costs', data: [51200, 54800, 53100, 56200, 58900] },
]"
[labels]="['Jan', 'Feb', 'Mar', 'Apr', 'May']"
[height]="240"
/>
typeSeries shapeNotes
line{ name, data: number[] }Crosshair tooltip; dash patterns distinguish series without color.
areasameFilled baseline under each line.
barsameGrouped bars per category; use stacked for cumulative bands.
scatter{ kind: 'xy', name, data: { x, y, label? }[] }Numeric x/y axes; optional xDomain / yDomain.
pie{ kind: 'radial', name, data: { label, value }[] }Exactly one radial series.
donutsame as pieInner hole sized by donutRatio (default 0.55).

All series accept an optional color?: 1 | 2 | 3 | 4 | 5 to pick a chart palette slot. Numeric series may also set stackId so compatible series stack together.

InputTypeDefaultNotes
typeChartType ('line' | 'area' | 'bar' | 'scatter' | 'pie' | 'donut')'line'Chart kind.
seriesChartSeriesInput[] (required)See chart types above.
labelsstring[][]X-axis category labels (cartesian types).
stackedbooleanfalseStack compatible bar / area series.
animatedbooleanfalseAnimate marks on first paint; disabled under prefers-reduced-motion.
valueFormatChartValueFormatter | nullnullFormats numbers in axes, tooltips, and live region.
labelFormatChartLabelFormatter | nullnullFormats category / datum labels.
xDomain[min, max] | nullnullExplicit scatter x extent.
yDomain[min, max] | nullnullExplicit y extent (cartesian + scatter).
donutRationumber0.55Inner-radius fraction for donut (clamped 0–1).
heightnumber240SVG height (coordinate units); width is responsive via viewBox.
showLegendbooleantrueLegend below the plot.
showGridbooleantrueGridlines (cartesian + scatter).
yTicksnumber5Approximate tick count.
ariaLabelstring''Accessible name; auto-generated from series when empty.
OutputPayloadNotes
pointHoverChartPointEvent | nullPointer moves over a datum, keyboard focus changes, or pointer leaves the plot.
pointClickChartPointEventClick on the active datum, or Enter / Space while focused.

ChartPointEvent includes chartType, seriesIndex, dataIndex, seriesName, label, value, optional x (scatter), and originalDatum.

Pass functions that receive the raw value/label plus a ChartFormatContext (chartType, location: 'axis' | 'tooltip' | 'legend' | 'live-region', optional indices and datum).

<ax-chart
type="line"
[series]="series"
[labels]="labels"
[valueFormat]="currency"
[labelFormat]="month"
/>
const currency: ChartValueFormatter = (value) =>
new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(value);
const month: ChartLabelFormatter = (label) => `${label} 2026`;

The library also exports formatChartValue, formatChartLabel, and formatPercent from @axisui-ng/charts for reuse in custom formatters.

<ax-chart
type="scatter"
[series]="[
{
kind: 'xy',
name: 'Product A',
data: [
{ x: 12, y: 240, label: 'Jan' },
{ x: 18, y: 310, label: 'Feb' },
],
},
]"
[xDomain]="[0, 40]"
[yDomain]="[0, 500]"
/>
<ax-chart
type="donut"
[donutRatio]="0.6"
[series]="[
{
kind: 'radial',
name: 'Traffic',
data: [
{ label: 'Organic', value: 42 },
{ label: 'Paid', value: 28 },
{ label: 'Email', value: 18 },
],
},
]"
/>
<ax-chart
type="bar"
[stacked]="true"
[series]="[
{ name: 'Organic', data: [120, 140, 135], stackId: 'visits' },
{ name: 'Paid', data: [80, 95, 88], stackId: 'visits' },
]"
[labels]="['Jan', 'Feb', 'Mar']"
/>

The SVG is focusable (tabindex="0"). Screen-reader instructions are linked via aria-describedby; focused navigation updates a polite live region.

KeyBehavior
← / →Previous / next datum (category index for cartesian & radial; keyboard order for scatter).
↑ / ↓Previous / next series (cartesian & scatter only).
Home / EndFirst / last datum in the current series.
Enter / SpaceEmit pointClick for the active datum.
EscapeClear keyboard selection and tooltip.

On pointer leave, keyboard selection is restored when the chart retains focus.

role="img" with an ariaLabel summarizing the chart (or your override). Cartesian charts also expose a visually-hidden data table with the same values. Series colors resolve to OKLCH theme tokens so they adapt to light/dark and industry presets.

Empty input shows No data; invalid series/type combinations show Invalid chart data.

Pro component — see ProWatermark for how the watermark/gating works.

Interactive examples live in Storybook under Pro / Chart — including stacked, scatter, pie/donut, formatters, events, animation, and empty/invalid states. Run pnpm storybook to explore them.