Charts
LineChart
Trends over time with a clear line between what happened and what is expected. Actual values are solid, a forecast is dashed, and a target stays on the chart.
When to use it #
Use LineChart for a handful of series that share an x axis: revenue against plan, a forecast that continues the actuals, a scenario next to the current path. For a single value per period, BarChart usually reads faster.
Import #
npm i tally-chartsimport { LineChart } from 'tally-charts'
import 'tally-charts/theme.css'Examples #
| Month | Actual | Forecast |
|---|---|---|
| Jan | $410 | no value |
| Feb | $455 | no value |
| Mar | $498 | no value |
| Apr | $530 | no value |
| May | $590 | no value |
| Jun | $640 | $640 |
| Jul | no value | $700 |
| Aug | no value | $745 |
| Sep | no value | $790 |
| Oct | no value | $850 |
import { LineChart } from 'tally-charts'
import type { ExampleMeta } from '../types'
export const meta = {
id: 'line-chart/revenue-forecast',
title: 'Monthly revenue, actual and forecast',
rscSafe: true,
} satisfies ExampleMeta
const months = [
{ month: 'Jan', actual: 410, forecast: null },
{ month: 'Feb', actual: 455, forecast: null },
{ month: 'Mar', actual: 498, forecast: null },
{ month: 'Apr', actual: 530, forecast: null },
{ month: 'May', actual: 590, forecast: null },
{ month: 'Jun', actual: 640, forecast: 640 },
{ month: 'Jul', actual: null, forecast: 700 },
{ month: 'Aug', actual: null, forecast: 745 },
{ month: 'Sep', actual: null, forecast: 790 },
{ month: 'Oct', actual: null, forecast: 850 },
]
// Props stay serializable (no functions): the page is a server component.
export default function RevenueForecast() {
return (
<LineChart
data={months}
x="month"
series={[
{ id: 'actual', label: 'Actual', value: 'actual' },
{ id: 'forecast', label: 'Forecast', value: 'forecast', style: 'forecast' },
]}
forecastFrom="Jul"
target={{ value: 800, label: 'Target' }}
format="currency-compact"
height={260}
title={meta.title}
description="Revenue grew from 410 to 640 over six months; the forecast reaches 850 in October."
/>
)
}
underlay takes marks that sit under the lines, such as an <Area> on a time axis. The chart draws in a fixed order: the grid first, then the underlay, then the target and band, then the series, then the axes, and last your children. So an underlay is above the grid and under every line, and children stay above the lines. Here last year's orders are a soft area behind this year's line. The underlay is a plain element, so every prop of this chart is still serializable.
import { Area, LineChart } from 'tally-charts'
import type { ExampleMeta } from '../types'
export const meta = {
id: 'line-chart/orders-last-year',
title: 'Weekly orders this autumn, over the same weeks last year',
rscSafe: true,
} satisfies ExampleMeta
// One row per Monday: this year's orders, and the same week a year earlier.
const weeks = [
{ at: '2026-08-03', orders: 1210, lastYear: 1100 },
{ at: '2026-08-10', orders: 1260, lastYear: 1130 },
{ at: '2026-08-17', orders: 1190, lastYear: 1090 },
{ at: '2026-08-24', orders: 1320, lastYear: 1180 },
{ at: '2026-08-31', orders: 1380, lastYear: 1215 },
{ at: '2026-09-07', orders: 1355, lastYear: 1200 },
{ at: '2026-09-14', orders: 1440, lastYear: 1260 },
{ at: '2026-09-21', orders: 1510, lastYear: 1300 },
{ at: '2026-09-28', orders: 1480, lastYear: 1285 },
{ at: '2026-10-05', orders: 1570, lastYear: 1340 },
{ at: '2026-10-12', orders: 1640, lastYear: 1385 },
{ at: '2026-10-19', orders: 1695, lastYear: 1420 },
]
// Props stay serializable (no functions): the page is a server component. The `underlay` is a
// plain element, so it crosses the server boundary like any other prop.
export default function OrdersLastYear() {
return (
<LineChart
data={weeks}
x={{ type: 'time', field: 'at' }}
series={[{ id: 'orders', label: 'This year', value: 'orders' }]}
// Drawn after the grid and before the line, so last year sits behind this year.
underlay={<Area data={weeks} x="at" y="lastYear" tone="neutral" />}
domain={[0, 2000]}
format="number"
height={260}
title={meta.title}
description="Orders grew from 1,210 to 1,695 a week, 19% above the same week last year, which reached 1,420."
/>
)
}
Props #
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
activeId | Id | null | — | No | — |
animate | boolean | — | No | — |
aria-labelledby | string | — | No | Id of an element that names the chart; it wins over |
band | LineBand<D> | — | No | A soft band between two values, e.g. the likely range of a forecast. |
chartId | string | — | No | Prefix for pattern and mask ids. React's |
children | ReactNode | — | No | — |
className | string | — | No | — |
data | readonly D[] | — | Yes | — |
dataTable | boolean | DataTableOptions | true | No | Hidden data table for screen readers: |
description | string | — | No | Accessible description, usually the takeaway sentence. |
dimInactive | boolean | — | No | — |
domain | readonly [number, number] | every series, the band and the target, rounded to nice ticks | No | Value domain. Default: every series, the band and the target, rounded to nice ticks; zero isn't forced. The order may be reversed: |
empty | ReactNode | "No data" | No | Rendered instead of the plot when |
forecastFrom | TimeInput | — | No | Shade from here to the end, e.g. the first forecast month: a category, or a date on a time axis. The shading starts halfway between it and the x before it. |
format | FormatSpec | 'number' | No | Default 'number'. |
grid | boolean | true | No | Horizontal grid lines at the value ticks ('all' when |
height | number | 240 unless `aspectRatio` is set | No | Height in px. Default 240 unless |
initialWidth | number | 640 | No | Width used for server rendering and the first client render. Default 640. |
interactive | boolean | true | No | Default true. With false the chart is static: no points are registered, so it has no tab stop, no keyboard hint, no pointer response and no tooltip ( |
keyboardHint | string | "Use arrow keys to move between points, Home and End for first and last, Escape to clear.", plus " Press Enter to select." while the active point (or the first, before one is active) can be selected with `onSelect` | No | Instructions read with the chart when it takes keyboard focus. Default: "Use arrow keys to move between points, Home and End for first and last, Escape to clear.", plus " Press Enter to select." while the active point (or the first, before one is active) can be selected with |
margin | Partial<Margin> | — | No | — |
onActiveChange | (id: Id | null, point: ChartPoint<D> | null) => void | — | No | Called with the new active id, and its point; |
onSelect | (id: Id, point: ChartPoint<D>) => void | — | No | Called on click, Enter or Space; |
radius | number | 4 | No | Dot radius in px. Default 4. |
series | readonly LineSeries<D>[] | — | Yes | — |
style | CSSProperties | — | No | — |
target | number | { value: number; label?: string } | — | No | — |
title | string | — | No | Accessible name of the chart; also the default caption of the data table. |
tooltip | ChartTooltip<D> | true | No | Tooltip on hover and focus: |
underlay | ReactNode | — | No | Marks drawn under the series, above the grid, e.g. an |
width | number | — | No | Fixed width in px; turns off container measuring. |
x | Accessor<D, string | number> | (TimeScaleSpec<D> & { field: Accessor<D, TimeInput> }) | — | Yes | The x of each row. An accessor puts categories on a point scale: each value appears once, repeats are skipped, and point ids are the values as strings, so |
xAxis | TickSpec | 'none' | 'all' | No | x axis ticks, or 'none'. Default 'all'. |
xAxisFormat | AxisFormat | the category itself, or 'auto' dates on a time axis | No | x axis labels; tooltip headers, announcements and the data table's x cells use the same format. Default: the category itself, or 'auto' dates on a time axis. |
yAxis | TickSpec | 'none' | 'all' (about 5) | No | Value axis ticks, or 'none'. The grid follows them. Default 'all' (about 5). |
yAxisFormat | AxisFormat | `format` | No | Value axis labels. Default: |
Keyboard and screen readers #
LineChart is built on Chart, so it follows the same keyboard model as the other charts: it is a single tab stop, and tabbing in shows the first point with its tooltip and announces it. A click that focuses the chart does not. ← and → (and ↑ and ↓) move to the previous or next point, and Home and End jump to the first and last. Enter or Space selects the active point when the chart has onSelect, but only a point that can be selected (a point with selectable: false never promises Enter). Esc clears the active point; it is only consumed when a point is active, so an enclosing dialog still closes.
The widget’s description ends with a keyboard hint (“Use arrow keys to move between points, Home and End for first and last, Escape to clear.”, plus “Press Enter to select.” with onSelect). keyboardHint replaces it, for example to translate it, and keyboardHint="" turns it off.
Screen readers get the chart title and description, then an announcement for each point the keyboard moves to: the position, the x and each series’ value, such as “9 of 9, Dec, 36.0% on the current path, 37.6% with changes”. A visually hidden data table follows the chart with every value, and dataTable renames its caption and headers or turns it off. The underlay is drawing only: it is hidden from assistive technology like the rest of the SVG, so put what it shows in the description or the data, as the example does with last year’s orders.
The full model is in the accessibility guide.