Slope chart
Before and after on two axes: lines draw in, rank moves sit beside each value, and switching datasets slides every line to its new slope.
npx shadcn@latest add @silicon-ui/slope-chartInstallation
With the shadcn CLI
npx shadcn@latest add @silicon-ui/slope-chartManually
Install the dependencies
npm install motionCopy these files into your project
- components/silicon-ui/slope-chart/slope-chart.tsx
- components/silicon-ui/slope-chart/slope-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* | SlopeItem[] | — |
label*What is measured, such as "Conversion rate by channel". Names the chart for assistive technology. | string | — |
startLabel*Heading of the first column, such as "Q1". | string | — |
endLabel*Heading of the second column, such as "Q2". | string | — |
formatValue | (value: number) => string | — |
formatChangeFormats the change in the tooltip. Defaults to the difference in formatValue's terms. | (change: number, item: SlopeItem) => string | — |
heightPlot height in pixels. Defaults to 44 pixels per item. | number | — |
highlightKeyThe item drawn in the accent, such as the one the story is about. | string | null | null |
activeKeyControlled item in focus. The others fade while one is in focus. | string | null | — |
onActiveChange | (key: string | null) => void | — |
ranksRank movement beside each end value. | boolean | true |
emptyLabel | string | "No data" |
ref | Ref<HTMLElement> | — |
className | string | — |
Dependencies
- npm
- motion
- Registry
- silicon-motion-tokens