LineChart
Displays line or area series. Values use application-defined units. The y-axis domain derives from the data.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
series | ChartSeries[] | — | One or more line/area series with values, color, and optional label. |
height | number | 84 | Chart height in pixels. |
yLabels | [string, string, string] | false | — | Custom axis labels. Pass false to hide entirely. |
min | number | — | Pin the bottom of the y domain. |
max | number | — | Pin the top of the y domain. |
formatValue | (value: number) => string | — | Formats the derived y-axis labels. |
xLabels | string[] | — | X-axis category labels. |
legend | { label: string; color: string }[] | — | Explicit legend entries. Auto-derived from series labels when omitted. |
renderTooltip | (index: number) => ReactNode | — | Tooltip for hover crosshair. Use ChartTooltipHeader/ChartTooltipRow for a styled tooltip. |
onHoverChange | (index: number | null) => void | — | Sync crosshairs across multiple charts. |
hoverIndex | number | null | — | Controlled hover index for synced charts. |
xLabelEvery | number | — | Render every nth x-axis label when labels need thinning. |
Usage
Single area series
Multiple series with tooltip
With x-axis labels
Tooltips
Compose custom tooltips with ChartTooltipHeader and ChartTooltipRow. The tooltip flips sides past the horizontal midpoint of the card so it stays inside the card.
import {
LineChart,
ChartTooltipHeader,
ChartTooltipRow,
} from "@solarius/onset";
<LineChart
series={[
{ values: cpuData, color: "var(--m-color-primary)", label: "CPU" },
{ values: memData, color: "var(--m-color-warn)", label: "Memory" },
]}
renderTooltip={(i) => (
<>
<ChartTooltipHeader>Jan {i + 1}, 2025</ChartTooltipHeader>
<ChartTooltipRow
swatch="var(--m-color-primary)"
label="CPU"
value={`${cpu[i]}%`}
/>
<ChartTooltipRow
swatch="var(--m-color-warn)"
label="Memory"
value={`${mem[i]}%`}
/>
<ChartTooltipRow
swatch="var(--m-color-ok)"
label="Network"
value={`${net[i]} MB/s`}
/>
</>
)}
/>;