Skip to content
Hazine

Line Chart with Range Switch

Single-series line chart in a card whose header holds a headline value, a signed delta and a range switch that drives all three. Use it for one primary metric such as revenue or active users.

How it differs. The range control sits in the header and drives the headline, the delta, the plot and a stat strip together, so chart and stat tile are one component with a dashed previous-period line.

Install

pnpm dlx shadcn@latest add @hazine/line-chart-range-switch

Adds 2 files, 3 shadcn primitives (button, card, chart), 1 Hazine item (@hazine/use-controllable-state), and 2 packages (lucide-react, recharts).

First time? Add the registry to components.json
{
  "registries": {
    "@hazine": "https://api.hazine.dev/r/{name}.json"
  }
}

Needed once per project. Items resolve each other through the @hazine namespace.

Props13

titlerequired
string
Name of the metric. It labels the card, the tooltip and the data table.
rangesrequired
LineChartRange[]
value
string
`value` of the selected range.
defaultValue
string
onValueChange
(value: string) => void
aggregate
LineChartAggregate = "sum"
How points become the headline: their total, the latest point or their mean.
locale
string = "en-US"
formatOptions
Intl.NumberFormatOptions = DEFAULT_FORMAT
Passed to Intl.NumberFormat for every figure.
loading
boolean = false
Shows skeletons while the selected range is fetched. The switch stays usable.
error
string
What went wrong and what to do, shown in place of the plot.
onRetry
() => void
empty
React.ReactNode
Replaces the default message when the selected range has no points.
labels
Partial<LineChartRangeSwitchLabels>
Overrides for the text the component writes itself, including the two sentence builders for the hidden caption and the plot name.

Also accepts every prop of Omit<React.ComponentProps<typeof Card>, "title" | "defaultValue">.

Accessibility

Pattern
Chart with text alternative, Radio Group (APG, opens in a new tab)
Keyboard
Keyboard support for Line Chart with Range Switch
KeyEffect
TabMoves to the selected range, then to the plot, or to Try again when loading failed
Arrow keys on the rangeSelects the previous or next available range and updates the headline, the delta, the plot and the stat strip
Space on the rangeSelects the focused range
Arrow Left, Arrow Right on the plotMoves the tooltip to the previous or next point
Enter or Space on Try againAsks for the range again. When the message leaves, focus moves to the selected range
Screen reader

A figure with a hidden caption that states the total, the change and the extremes. The range is a group of native radios in a fieldset, the headline is a polite live region, the plot is an image named by its finding, and a hidden table lists every point.

  • Announces: {value}, {Up or Down} {delta} {baseline}
  • Announces: Loading {title}, {range}
  • Announces: {error}
Reduced motion
The line is never animated. The loading skeleton stops pulsing.
Checked
Not checked yet. Automated results appear here once CI has run.

Dependencies6

  • button
  • card
  • chart
  • @hazine/use-controllable-state
  • lucide-react
  • recharts

Filled chips are registry items the CLI adds for you. Outlined chips are npm packages.

Tokens shipped0

None. The item is styled by the tokens your theme already has.