# Line chart

Up to five series over time as lines, for comparing trends.

- Family: charts
- Import: `import { LineChart } from "@senvenli/react/charts";`
- Page: https://design.senvenli.com/docs/components/line-chart
- JSON: https://design.senvenli.com/docs/components/line-chart.json

## Example: Orders by region

Three series over the same months; the third is dashed, so they differ by more than hue.

```tsx
import { LineChart } from "@senvenli/react/charts";

const ORDERS = [
  { month: "Jan", north: 320, south: 210, west: 150 },
  { month: "Feb", north: 345, south: 232, west: 148 },
  { month: "Mar", north: 390, south: 228, west: 171 },
  { month: "Apr", north: 372, south: 260, west: 196 },
  { month: "May", north: 418, south: 281, west: 204 },
  { month: "Jun", north: 455, south: 276, west: 239 },
];

export default function Example() {
  return (
    <LineChart
      title="Orders"
      period="Jan–Jun 2026"
      data={ORDERS}
      index="month"
      categories={["north", "south", "west"]}
      labels={{ north: "North", south: "South", west: "West" }}
      allowDecimals={false}
    />
  );
}
```

## Examples

### With a target line

A dashed reference line with its label at the end.

```tsx
import { LineChart } from "@senvenli/react/charts";

const REVENUE = [
  { month: "Jan", revenue: 38200 },
  { month: "Feb", revenue: 41500 },
  { month: "Mar", revenue: 47900 },
  { month: "Apr", revenue: 45100 },
  { month: "May", revenue: 52300 },
  { month: "Jun", revenue: 56800 },
];
const usd = new Intl.NumberFormat("en", { style: "currency", currency: "USD", notation: "compact" });

export default function Example() {
  return (
    <LineChart
      title="Monthly revenue"
      period="Jan–Jun 2026"
      total={usd.format(281800)}
      data={REVENUE}
      index="month"
      categories={["revenue"]}
      labels={{ revenue: "Revenue" }}
      valueFormatter={usd.format}
      referenceLines={[{ value: 50000, label: "Target" }]}
    />
  );
}
```

### Missing values

A null leaves a gap; `connectNulls` joins the line across it.

```tsx
import { LineChart } from "@senvenli/react/charts";

// The store was closed in April: no figure, which is not the same as zero.
const VISITS = [
  { month: "Jan", store: 1240, online: 3100 },
  { month: "Feb", store: 1310, online: 3350 },
  { month: "Mar", store: 1180, online: 3600 },
  { month: "Apr", store: null, online: 3820 },
  { month: "May", store: 1420, online: 4010 },
  { month: "Jun", store: 1505, online: 4260 },
];

export default function Example() {
  return (
    <LineChart
      title="Visits"
      period="Jan–Jun 2026"
      data={VISITS}
      index="month"
      categories={["online", "store"]}
      labels={{ online: "Online", store: "In store" }}
      connectNulls
    />
  );
}
```

## Guidelines

### When to use it

- Comparing a few series over the same periods.

### Use something else when

- [area-chart](https://design.senvenli.com/docs/components/area-chart.md): One total and its trend.

## Accessibility

Keyboard:

- Arrow left / right: Moves between data points; the tooltip follows.

Built in:

- A "Show as table" button shows the same data as a table, which screen readers get by default.

You provide:

- A title that says what the figure is.

## API reference

### LineChart

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| title | `string` |  | no | What the chart shows ("Revenue"), over it; leave it out when a card or a heading already says so. |
| aria-label | `string` |  | no | Names the chart when it has no visible `title` (a card's heading already says what it shows). |
| period | `string` |  | no | The period it covers ("June–September 2026"). |
| total | `React.ReactNode` |  | no | The headline figure, in `metric-medium` ("€ 184,2k"). |
| data | `readonly T[]` |  | yes |  |
| index | `keyof T & string` |  | yes | The x key: the period or category of each row. |
| categories | `readonly (keyof T & string)[]` |  | yes | The series keys, in order; the first is the product's own figure (`ds-chart-1`). |
| labels | `Readonly<Partial<Record<string, string>>>` |  | no | Series names by key ("web" → "Website"); the key by default. |
| valueFormatter | `ChartValueFormatter` |  | no | Shared by axis, tooltip and table (Intl): "€ 48.920". |
| indexFormatter | `(value: unknown) => string` |  | no | The index label in the tooltip and the table ("August 2026"). |
| indexLabel | `string` |  | no | The index column's header in the data table; "Period" for time charts, "Category" for BarChart. |
| height | `number` |  | no | The plot's height in px; 240 by default. |
| isLoading | `boolean` |  | no |  |
| emptyState | `React.ReactNode` |  | no | Shown instead of the plot when there is no data: an `EmptyState size="small"` or text; "No data" by default. |
| allowDecimals | `boolean` |  | no | `false` for whole counts (orders, new customers): the value axis steps by whole numbers, so a small count reads 0 / 1 / 2 / 3, never 0.7 / 1.4 / 2.1. Fractional steps by default. Percent bars keep their 0–100% steps. |
| referenceLines | `readonly ChartReferenceLine[]` |  | no | A target or an average: dashed `ds-border-bold` with a label at its end. |
| connectNulls | `boolean` |  | no | Join across missing values; gaps stay gaps by default. |

### Tokens it reads

`--ds-background-neutral`, `--ds-border`, `--ds-border-bold`, `--ds-border-focused`, `--ds-chart-1`, `--ds-chart-2`, `--ds-chart-3`, `--ds-chart-4`, `--ds-chart-5`, `--ds-chart-neutral`, `--ds-link`, `--ds-radius-medium`, `--ds-radius-small`, `--ds-radius-xsmall`, `--ds-shadow-overlay`, `--ds-space-050`, `--ds-space-075`, `--ds-space-100`, `--ds-space-150`, `--ds-space-200`, `--ds-space-300`, `--ds-surface-overlay`, `--ds-surface-raised`, `--ds-text`, `--ds-text-danger`, `--ds-text-subtle`, `--ds-text-subtlest`, `--ds-text-success`

## Related

- [area-chart](https://design.senvenli.com/docs/components/area-chart.md)
- [composed-chart](https://design.senvenli.com/docs/components/composed-chart.md)
