GooseUI

Components

Chart

New

Line, area and bar charts drawn as inline SVG on the server. Data comes through props, colors from the --chart-1..5 theme variables, hovering or focusing a point or bar shows a small tooltip next to it, rendered on the server and revealed by CSS, and a hidden table repeats the data for screen readers. No JavaScript, no charting library.

Preview

0100200300400JanFebMarAprMayJun
  • Desktop
  • Mobile
Visitors per month
MonthDesktopMobile
Jan18680
Feb305200
Mar237120
Apr273190
May209130
Jun314140

Installation

npx shadcn@latest add @gooseui/chart
pnpm dlx shadcn@latest add @gooseui/chart
yarn dlx shadcn@latest add @gooseui/chart
bunx --bun shadcn@latest add @gooseui/chart

Usage

import { Chart } from "@/components/ui/chart"

export default function Example() {
  return (
    <Chart
      type="line"
      title="Visitors per month"
      categories={["Jan", "Feb", "Mar", "Apr", "May", "Jun"]}
      series={[
        { name: "Desktop", values: [186, 305, 237, 273, 209, 314] },
        { name: "Mobile", values: [80, 200, 120, 190, 130, 140] },
      ]}
    />
  )
}

Examples

Area

Same data as a filled area with a linear curve.

0100200300400JanFebMarAprMayJun
  • Desktop
  • Mobile
Visitors per month
MonthDesktopMobile
Jan18680
Feb305200
Mar237120
Apr273190
May209130
Jun314140
<Chart type="area" curve="linear" categories={months} series={series} />

Bar

Grouped bars; negative values go below the zero line.

-1000100200300400JanFebMarAprMayJun
  • Desktop
  • Mobile
Visitors per month
MonthDesktopMobile
Jan18680
Feb305-40
Mar237120
Apr273190
May209-30
Jun314140
<Chart type="bar" categories={months} series={series} />

Custom colors and formatting

color takes any CSS color and formatValue formats ticks, tooltips and the table.

$0k$10k$20k$30k$40kJanFebMarAprMayJun
Revenue, thousand dollars
MonthRevenue
Jan$12k
Feb$18k
Mar$15k
Apr$24k
May$31k
Jun$28k
<Chart
  type="area"
  categories={months}
  series={[{ name: "Revenue", color: "var(--primary)", values: [12, 18, 15, 24, 31, 28] }]}
  formatValue={(v) => `$${v}k`}
  showLegend={false}
/>

Props

PropTypeDefaultDescription
type"line" | "area" | "bar""line"Chart kind
categoriesstring[]-X axis labels
series{ name: string; values: (number | null)[]; color?: string }[]-Series: name, values (null leaves a gap) and optional color, default --chart-1..5
curve"linear" | "smooth""smooth"Line and area curve
ticksnumber5Approximate number of Y ticks
showGridbooleantrueHorizontal grid lines
showLegendbooleantrueLegend under the chart
showDotsbooleantrueDots on points of line and area
tooltipbooleantrueTooltip at each point or bar on hover and keyboard focus (Tab walks the points series by series)
formatValue(value: number) => string-Formats ticks, tooltips and the table
titlestring"Chart"Accessible name and caption of the hidden table
categoryHeaderstring"Category"Header of the first column of the hidden table
widthnumber600SVG coordinate width; a smaller number gives larger text
heightnumber300SVG coordinate height; the box keeps width to height
durationnumber900Draw-in animation in ms; 0 turns it off