preskok/ui

Chart (helpers)

Core chart context, tooltip, legend, and axes used by Preskok chart components.

Installation

pnpm dlx @preskok-org/ui@latest add chart

Usage

import { Area, AreaChart as AreaChartPrimitive } from "recharts"
 
import {
  CartesianGrid,
  Chart,
  ChartLegend,
  ChartLegendContent,
  ChartTooltip,
  ChartTooltipContent,
  XAxis,
  YAxis,
} from "@/registry/preskok/ui/preskok-ui/chart"
 
const data = [
  { day: "Mon", Desktop: 120, Mobile: 80 },
  { day: "Tue", Desktop: 200, Mobile: 130 },
]
 
const config = {
  Desktop: { label: "Desktop", color: "#2563eb" },
  Mobile: { label: "Mobile", color: "#60a5fa" },
}
 
export function ChartDemo() {
  return (
    <Chart data={data} dataKey="day" config={config}>
      {() => (
        <AreaChartPrimitive data={data}>
          <CartesianGrid strokeDasharray="3 3" />
          <XAxis />
          <YAxis />
          <ChartLegend content={<ChartLegendContent />} />
          <ChartTooltip content={<ChartTooltipContent />} />
          <Area
            type="monotone"
            dataKey="Desktop"
            stroke="#2563eb"
            fill="#2563eb"
            fillOpacity={0.3}
          />
          <Area
            type="monotone"
            dataKey="Mobile"
            stroke="#60a5fa"
            fill="#60a5fa"
            fillOpacity={0.3}
          />
        </AreaChartPrimitive>
      )}
    </Chart>
  )
}

Features

  • Context for shared chart props and selection state
  • Legend with selection filtering
  • Tooltip with configurable content
  • Axes helpers with sensible defaults