Line chart
A multi-series line chart with a gliding crosshair, legend toggles, and paths that morph between ranges.
npx shadcn@latest add @silicon-ui/line-chartInstallation
With the shadcn CLI
npx shadcn@latest add @silicon-ui/line-chartManually
Install the dependencies
npm install motionCopy these files into your project
- components/silicon-ui/line-chart/line-chart.tsx
- components/silicon-ui/line-chart/line-chart.module.css
Add the foundation, once per app, for the design and motion tokens
npx shadcn@latest add @silicon-ui/silicon-foundation
Usage
API reference
| Prop | Type | Default |
|---|---|---|
data* | LineChartDatum[] | — |
series* | LineChartSeries[] | — |
label*What is measured, such as "Signups". Names the chart for assistive technology. | string | — |
unitUnit after each value in the tooltip, such as "ms". | string | "" |
heightPlot height in pixels. The width follows the container. | number | 220 |
formatValueFormats values in the tooltip and data table. | (value: number, series: LineChartSeries) => string | — |
formatTickFormats the value axis. Defaults to a compact number, such as 1.2K. | (value: number) => string | value => compact.format(value) |
hiddenSeriesControlled hidden series keys. | string[] | — |
defaultHiddenSeries | string[] | — |
onHiddenSeriesChange | (hidden: string[]) => void | — |
onActiveChangeCalled as the crosshair moves, and with null when it leaves. Use it to drive a headline readout. | (index: number | null, datum: LineChartDatum | null) => void | — |
loadingKeeps the current lines on screen, dimmed, while the next range loads. | boolean | false |
emptyLabelShown when there are no points. | string | "No data for this range" |
legendSeries toggles above the plot. Shown by default when there is more than one series. | boolean | — |
categoryLabelHeader of the first column in the data table read by screen readers. | string | "Date" |
curveSmooth monotone curves that never swing past the data, or straight segments. | "smooth" | "linear" | "smooth" |
ref | Ref<HTMLElement> | — |
className | string | — |
Dependencies
- npm
- motion
- Registry
- silicon-motion-tokens