Line Chart
Multi-series line. Default and Motion variants.
Examples
Installation
Default is a ready-made wrapper from the registry. Motion is the composable engine at @cronus-ui/ui/charts (peer visx + motion).
npx cronus-ui add line-chart
import { LineChart } from "@cronus-ui/ui";
Usage
Same composable shell as AreaChart. Add YAxis with matching yAxisId for biaxial charts, ProjectionLine for a forecast, or ProfitLossLine for a sign-split series.
import { LineChart, Line, Grid, XAxis, ChartTooltip } from "@cronus-ui/ui/charts";<LineChart data={data}><Grid horizontal /><Line dataKey="users" stroke="var(--chart-line-primary)" /><Line dataKey="pageviews" stroke="var(--chart-line-secondary)" /><XAxis /><ChartTooltip /></LineChart>
Components
Motion API — compose these under the chart root. Default wrapper props are in Default API below.
LineChart
Root that sizes the SVG, provides scales, and hosts series children.
| Prop | Type | Default | Description |
|---|---|---|---|
data* | Record<string, unknown>[] | — | Rows with a date (or x) field and numeric series. |
xDataKey | string | "date" | Key for the x-axis. |
margin | `Partial<{ top, right, bottom, left }>` | { top: 40, right: 40, bottom: 40, left: 40 } | Plot margins. |
animationDuration | number | 1100 | Clip-reveal duration in ms. |
aspectRatio | string | "2 / 1" | CSS aspect ratio. |
status | "loading" | "ready" | "ready" | Loading ↔ ready choreography. |
xDomain | [Date, Date] | — | Visible x-range for brush zoom. |
className | string | — | Container class. |
Line
Stroked series with optional edge fade, markers, loading pulse, and a dashed tail.
| Prop | Type | Default | Description |
|---|---|---|---|
dataKey* | string | — | Y-value key. |
yAxisId | string | number | "left" | Scale group for dual axes. |
stroke | string | var(--chart-line-primary) | Line color. |
strokeWidth | number | 2.5 | Line width. |
curve | CurveFactory | curveNatural | d3 curve. |
fadeEdges | boolean | "left" | "right" | false | Fade the stroke at chart edges. |
dashFromIndex | number | — | Index from which the stroke becomes dashed. |
showMarkers | boolean | false | Point markers. |
Grid
Plot-area grid lines. Horizontal by default; optional shimmer while loading.
| Prop | Type | Default | Description |
|---|---|---|---|
horizontal | boolean | true | Show horizontal lines. |
vertical | boolean | false | Show vertical lines. |
numTicksRows | number | 5 | Horizontal line count. |
numTicksColumns | number | 10 | Vertical line count. |
stroke | string | var(--chart-grid) | Line color while ready. |
strokeDasharray | string | "4,4" | Dash pattern. |
shimmer | boolean | false | Animate a band across horizontal lines. |
highlightRowValues | number[] | — | Rows drawn with alternate styling (e.g. zero). |
Background
Pattern fill for the plot area when you omit Grid, or as a texture behind series.
| Prop | Type | Default | Description |
|---|---|---|---|
pattern | PatternPresetId | "none" | — | Pattern preset. `none` renders nothing. |
color | string | var(--chart-grid) | Pattern stroke color. |
opacity | number | 1 | Pattern fill opacity. |
fadeHorizontal | boolean | true | Fade at left/right edges. |
YAxis
Value labels on the left or right. Pair `yAxisId` with series for dual axes.
| Prop | Type | Default | Description |
|---|---|---|---|
yAxisId | string | number | "left" | Scale group id. |
orientation | "left" | "right" | "left" | Which side to render. |
numTicks | number | 5 | Approximate tick count. |
formatLargeNumbers | boolean | true | Format 1000 as "1k". |
formatValue | (value: number) => string | — | Custom tick formatter. Overrides formatLargeNumbers. |
XAxis
Time-axis labels that fade when the crosshair passes.
| Prop | Type | Default | Description |
|---|---|---|---|
numTicks | number | 5 | Tick labels to show, including first and last. |
tickerHalfWidth | number | 50 | Fade radius around the date pill. |
tickMode | "data" | "domain" | "data" | `data` snaps labels to rows (crosshair-aligned). `domain` spaces ticks evenly. |
ChartTooltip
Motion tooltip: crosshair, series dots, floating panel, optional date pill. This is not the recharts ChartTooltip from `@cronus-ui/ui`.
| Prop | Type | Default | Description |
|---|---|---|---|
showDatePill | boolean | true | Animated date ticker on the x-axis. |
showCrosshair | boolean | true | Vertical crosshair. |
showDots | boolean | true | Dots on series at the hovered x. |
dotVariant | "dot" | "ring" | "dot" | Filled circle or ring. |
indicatorColor | string | (point) => string | — | Crosshair and dot color. |
indicatorDasharray | string | — | Dash pattern for the crosshair. |
indicatorFadeEdges | "both" | "top" | "bottom" | "none" | "both" | Vertical crosshair fade. |
matchCrosshair | boolean | false | Panel uses the crosshair spring when true. |
damping | number | 20 | Panel follow when matchCrosshair is false. 0 = instant. |
content | (props) => ReactNode | — | Custom tooltip renderer. |
rows | (point) => TooltipRow[] | — | Custom row generator. |
Dual Y axes
Give each series a yAxisId and render two YAxis children with matching ids and opposite orientations.
<LineChart data={data}><Line dataKey="users" yAxisId="left" stroke="var(--chart-1)" /><Line dataKey="revenue" yAxisId="right" stroke="var(--chart-2)" /><YAxis yAxisId="left" orientation="left" /><YAxis yAxisId="right" orientation="right" formatValue={(n) => MONEY.format(n)} /><XAxis /><ChartTooltip /></LineChart>
Dashed tail
Use dashFromIndex to project incomplete periods — solid through yesterday, dashed through today.
<Line dataKey="users" dashFromIndex={data.length - 2} dashArray="6,4" />
Projection
ProjectionLine draws a forecast from the last real point. Pair with SeriesMarkers or a custom tooltip row for the projected value.
import { LineChart, Line, ProjectionLine, Grid, XAxis, ChartTooltip } from "@cronus-ui/ui/charts";<LineChart data={data}><Grid horizontal /><Line dataKey="users" /><ProjectionLine dataKey="forecast" /><XAxis /><ChartTooltip /></LineChart>
Data format
type Point = {date: Date;users: number;pageviews: number;};const data: Point[] = [{ date: new Date("2026-01-01"), revenue: 12000, costs: 8500 },{ date: new Date("2026-01-02"), revenue: 13500, costs: 9200 },];
Theming
Motion charts read `--chart-*` aliases that map onto Cronus semantic tokens (`--cronus-chart-1`…`--cronus-chart-5`, `--cronus-border`, `--cronus-fg`, surfaces). Override the aliases or the tokens — never palette scales (`bg-zinc-900`). Default wrappers use `ChartConfig` with `var(--cronus-chart-*)` / `var(--cronus-primary)`.
Full token reference: Theming.
Dependencies
Default needs the recharts peer. Motion needs visx (and sometimes d3) as optional peers — install only what this chart uses.
bun add recharts
bun add @visx/curve @visx/responsive @visx/scale @visx/shape motion react-use-measure @visx/gradient
Default API
Generated from the Default wrapper's exported types. Motion subcomponents are documented above.
LineChartProps
Extends HTMLAttributes<HTMLDivElement>
| Prop | Type | Default | Description |
|---|---|---|---|
data* | Record<string, unknown>[] | — | — |
xKey | string | "date" | — |
series* | ChartSeries[] | — | — |
formatValue | (value: number, name: string) => string | — | — |