Components
Line Chart
A single series over time on a light grid. Pass a total to show a figure above the chart; add a delta to show how it moved.
Installation
bunx @happlyui/cli@latest add line-chart
Dependencies
npm packages
recharts@^3.8.1@remixicon/react@^4.6.0
Registry dependencies
These are automatically installed when you add this component.
happly-ui-utilschart-tooltip
Usage
import * as LineChart from "@/components/ui/line-chart"
<LineChart.Root
points={[{ label: "Mon, Aug 11", value: 12 }]}
total={{ label: "Total", value: 68, delta: 33.3, comparison: "vs previous period" }}
/>
Examples
Default
A total with its change, and a tooltip that also compares each point with the one before.
Card title
Total
68+33.3%vs previous period
<LineChart.Root
points={points}
total={{ label: "Total", value: 68, delta: 33.3, comparison: "vs previous period" }}
pointComparison="vs prev."
/>
Without delta
A total on its own, for a range with nothing before it to compare against.
Card title
Total
68
<LineChart.Root points={points} total={{ label: "Total", value: 68 }} />
API Reference
LineChart.Root
The header and chart. Fills its container's height.
| Prop | Type | Default | Description |
|---|---|---|---|
points | { label: string; value: number }[] | - | Points oldest first. label is the tooltip caption, so format dates first |
total | { label: string; value: number; delta?: number | null; comparison?: string } | - | A caption over a figure above the chart. Omit it and the chart takes the whole height |
pointComparison | string | - | When set, the tooltip shows each point's change from the one before, followed by this text |