Chart

One chart for a dashboard's numbers, drawn from labelled values as an area over time by default.

import { Chart, type ChartPoint } from "@produkto/ui/Chart";

const data: ChartPoint[] = [
  { label: "Mon", value: 12 },
  { label: "Tue", value: 28 },
  { label: "Wed", value: 19 },
  { label: "Thu", value: 34 },
  { label: "Fri", value: 41 },
  { label: "Sat", value: 30 },
  { label: "Sun", value: 45 },
];

const Example = () => (
  <div className="w-full max-w-2xl">
    <Chart config={{ value: { label: "Item 1" } }} data={data} />
  </div>
);

export default Example;

Usage

import { Chart } from "@produkto/ui/Chart";
<Chart
  config={{ value: { label: "This week" }, previous: { label: "Last week" } }}
  data={[
    { label: "Mon", value: 12, previous: 10 },
    { label: "Tue", value: 28, previous: 18 },
    { label: "Wed", value: 19, previous: 24 },
  ]}
/>

<Chart
  type="bars"
  data={[
    { label: "Item 1", value: 48 },
    { label: "Item 2", value: 35 },
    { label: "Item 3", value: 22 },
  ]}
/>

Examples

Type

type sets what the chart draws: area, the default, or line with nothing under it; "bars" draws a ranking, shown below.

import {
  Chart,
  type ChartPoint,
  type ChartTrendType,
} from "@produkto/ui/Chart";

const types: ChartTrendType[] = ["area", "line"];

const data: ChartPoint[] = [
  { label: "Mon", value: 12 },
  { label: "Tue", value: 28 },
  { label: "Wed", value: 19 },
  { label: "Thu", value: 34 },
  { label: "Fri", value: 41 },
  { label: "Sat", value: 30 },
  { label: "Sun", value: 45 },
];

const Example = () => (
  <div className="grid w-full max-w-2xl gap-4 sm:grid-cols-2">
    {types.map((type) => (
      <Chart data={data} key={type} type={type} />
    ))}
  </div>
);

export default Example;

Curve

curve joins the points with a smooth curve, the default, or with straight lines when sharp.

import {
  Chart,
  type ChartCurve,
  type ChartPoint,
} from "@produkto/ui/Chart";

const curves: ChartCurve[] = ["smooth", "sharp"];

const data: ChartPoint[] = [
  { label: "Mon", value: 12 },
  { label: "Tue", value: 28 },
  { label: "Wed", value: 19 },
  { label: "Thu", value: 34 },
  { label: "Fri", value: 41 },
  { label: "Sat", value: 30 },
  { label: "Sun", value: 45 },
];

const Example = () => (
  <div className="grid w-full max-w-2xl gap-4 sm:grid-cols-2">
    {curves.map((curve) => (
      <Chart curve={curve} data={data} key={curve} />
    ))}
  </div>
);

export default Example;

Label count

labelCount sets how many labels the axis spreads under the chart, the first and the last always among them: 5 by default, here beside 3.

import { Chart, type ChartPoint } from "@produkto/ui/Chart";

const counts: number[] = [5, 3];

const data: ChartPoint[] = [
  { label: "1 Nov", value: 12 },
  { label: "2 Nov", value: 28 },
  { label: "3 Nov", value: 19 },
  { label: "4 Nov", value: 34 },
  { label: "5 Nov", value: 41 },
  { label: "6 Nov", value: 30 },
  { label: "7 Nov", value: 45 },
  { label: "8 Nov", value: 38 },
  { label: "9 Nov", value: 52 },
  { label: "10 Nov", value: 47 },
  { label: "11 Nov", value: 58 },
  { label: "12 Nov", value: 49 },
  { label: "13 Nov", value: 61 },
  { label: "14 Nov", value: 66 },
];

const Example = () => (
  <div className="grid w-full max-w-2xl gap-4 sm:grid-cols-2">
    {counts.map((count) => (
      <Chart data={data} key={count} labelCount={count} />
    ))}
  </div>
);

export default Example;

Sparkline

sparkline leaves out the grid and the axis, for a small chart beside a figure, beside a chart with both as it is by default.

import { Chart, type ChartPoint } from "@produkto/ui/Chart";

const data: ChartPoint[] = [
  { label: "Mon", value: 12 },
  { label: "Tue", value: 28 },
  { label: "Wed", value: 19 },
  { label: "Thu", value: 34 },
  { label: "Fri", value: 41 },
  { label: "Sat", value: 30 },
  { label: "Sun", value: 45 },
];

const Example = () => (
  <div className="grid w-full max-w-2xl gap-4 sm:grid-cols-2">
    <Chart data={data} />
    <Chart data={data} sparkline />
  </div>
);

export default Example;

Previous

A point's previous value draws the period before as a dashed line behind the current one, and the tooltip lists both.

import { Chart, type ChartPoint } from "@produkto/ui/Chart";

const data: ChartPoint[] = [
  { label: "Mon", value: 12, previous: 10 },
  { label: "Tue", value: 28, previous: 18 },
  { label: "Wed", value: 19, previous: 24 },
  { label: "Thu", value: 34, previous: 20 },
  { label: "Fri", value: 41, previous: 29 },
  { label: "Sat", value: 30, previous: 26 },
  { label: "Sun", value: 45, previous: 31 },
];

const Example = () => (
  <div className="w-full max-w-2xl">
    <Chart data={data} />
  </div>
);

export default Example;

Value formatter

valueFormatter writes the tooltip's values, here as percentages; by default they are plain numbers.

import { Chart, type ChartPoint } from "@produkto/ui/Chart";

const data: ChartPoint[] = [
  { label: "Mon", value: 12 },
  { label: "Tue", value: 28 },
  { label: "Wed", value: 19 },
  { label: "Thu", value: 34 },
  { label: "Fri", value: 41 },
  { label: "Sat", value: 30 },
  { label: "Sun", value: 45 },
];

const Example = () => (
  <div className="w-full max-w-2xl">
    <Chart data={data} valueFormatter={(value) => `${value}%`} />
  </div>
);

export default Example;

Colour

color in a series' config paints it in place of the action colour, or of the muted grey for previous: any CSS colour, --chart-1 to --chart-5 first, or a light and a dark one.

import { Chart, type ChartPoint } from "@produkto/ui/Chart";

const data: ChartPoint[] = [
  { label: "Mon", value: 12, previous: 10 },
  { label: "Tue", value: 28, previous: 18 },
  { label: "Wed", value: 19, previous: 24 },
  { label: "Thu", value: 34, previous: 20 },
  { label: "Fri", value: 41, previous: 29 },
  { label: "Sat", value: 30, previous: 26 },
  { label: "Sun", value: 45, previous: 31 },
];

const Example = () => (
  <div className="w-full max-w-2xl">
    <Chart
      config={{
        value: { color: "var(--chart-2)" },
        previous: { color: { light: "#2e2a24", dark: "#e8e4dc" } },
      }}
      data={data}
    />
  </div>
);

export default Example;

Bars

type="bars" draws a ranked list, each value a bar against the largest, with its share of the total in the tooltip.

import { Chart, type ChartBar } from "@produkto/ui/Chart";

const data: ChartBar[] = [
  { label: "Item 1", value: 1284 },
  { label: "Item 2", value: 412 },
  { label: "Item 3", value: 356 },
  { label: "Item 4", value: 198 },
  { label: "Item 5", value: 141 },
];

const Example = () => (
  <div className="w-full max-w-sm">
    <Chart data={data} type="bars" />
  </div>
);

export default Example;

With icon

A bar's icon sits before its label in the bar and in the tooltip.

import {
  File01Icon,
  Folder01Icon,
  Image01Icon,
} from "@hugeicons/core-free-icons";
import { Chart, type ChartBar } from "@produkto/ui/Chart";

const data: ChartBar[] = [
  { label: "Item 1", value: 48, icon: Folder01Icon },
  { label: "Item 2", value: 35, icon: File01Icon },
  { label: "Item 3", value: 22, icon: Image01Icon },
];

const Example = () => (
  <div className="w-full max-w-sm">
    <Chart data={data} type="bars" />
  </div>
);

export default Example;

Media

A bar's media puts a picture of its own before the label in place of an icon, such as an avatar or a flag.

import { Avatar, AvatarFallback } from "@produkto/ui/Avatar";
import { Chart, type ChartBar } from "@produkto/ui/Chart";

const data: ChartBar[] = [
  {
    label: "User 1",
    value: 48,
    media: (
      <Avatar>
        <AvatarFallback>U1</AvatarFallback>
      </Avatar>
    ),
  },
  {
    label: "User 2",
    value: 35,
    media: (
      <Avatar>
        <AvatarFallback>U2</AvatarFallback>
      </Avatar>
    ),
  },
  {
    label: "User 3",
    value: 22,
    media: (
      <Avatar>
        <AvatarFallback>U3</AvatarFallback>
      </Avatar>
    ),
  },
];

const Example = () => (
  <div className="w-full max-w-sm">
    <Chart data={data} type="bars" />
  </div>
);

export default Example;

Loading

loading draws five thin skeleton rows in place of the bars, and loadingIcon puts a square before each when the bars lead with a picture.

import { Chart } from "@produkto/ui/Chart";

const Example = () => (
  <div className="flex w-full max-w-sm flex-col gap-8">
    <Chart data={[]} loading type="bars" />
    <Chart data={[]} loading loadingIcon type="bars" />
  </div>
);

export default Example;

Empty

With no rows, bars give way to a NotFound box saying there is nothing yet.

No items found
import { Chart } from "@produkto/ui/Chart";

const Example = () => (
  <div className="w-full max-w-sm">
    <Chart data={[]} type="bars" />
  </div>
);

export default Example;

Indicator

indicator on ChartTooltipContent draws each row's mark as a dot, the default, a line, a dashed line or nothing.

import {
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  type ChartConfig,
  type ChartTooltipIndicator,
} from "@produkto/ui/Chart";
import { Bar, BarChart, XAxis } from "recharts";

const indicators: ChartTooltipIndicator[] = ["dot", "line", "dashed", "none"];

const data: { day: string; one: number; two: number }[] = [
  { day: "Thu", one: 28, two: 41 },
  { day: "Fri", one: 33, two: 57 },
  { day: "Sat", one: 46, two: 64 },
];

const config = {
  one: { label: "Item 1", color: "var(--chart-1)" },
  two: { label: "Item 2", color: "var(--chart-4)" },
} satisfies ChartConfig;

const Example = () => (
  <div className="grid w-full max-w-2xl gap-4 sm:grid-cols-2">
    {indicators.map((indicator) => (
      <ChartContainer config={config} key={indicator}>
        <BarChart data={data} margin={{ top: 72 }}>
          <XAxis axisLine={false} dataKey="day" tickLine={false} />
          <ChartTooltip
            content={<ChartTooltipContent indicator={indicator} />}
            defaultIndex={1}
            position={{ y: 0 }}
          />
          <Bar dataKey="one" fill="var(--color-one)" radius={4} />
          <Bar dataKey="two" fill="var(--color-two)" radius={4} />
        </BarChart>
      </ChartContainer>
    ))}
  </div>
);

export default Example;

Show label

showLabel draws the heading of ChartTooltipContent, naming the point above its rows as it does by default, beside one with showLabel false that leaves it out.

import {
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  type ChartConfig,
} from "@produkto/ui/Chart";
import { Bar, BarChart, XAxis } from "recharts";

const data: { day: string; one: number; two: number }[] = [
  { day: "Thu", one: 28, two: 41 },
  { day: "Fri", one: 33, two: 57 },
  { day: "Sat", one: 46, two: 64 },
];

const config = {
  one: { label: "Item 1", color: "var(--chart-1)" },
  two: { label: "Item 2", color: "var(--chart-4)" },
} satisfies ChartConfig;

const Bars = ({ showLabel }: { showLabel?: boolean }) => (
  <ChartContainer config={config}>
    <BarChart data={data} margin={{ top: 72 }}>
      <XAxis axisLine={false} dataKey="day" tickLine={false} />
      <ChartTooltip
        content={<ChartTooltipContent showLabel={showLabel} />}
        defaultIndex={1}
        position={{ y: 0 }}
      />
      <Bar dataKey="one" fill="var(--color-one)" radius={4} />
      <Bar dataKey="two" fill="var(--color-two)" radius={4} />
    </BarChart>
  </ChartContainer>
);

const Example = () => (
  <div className="grid w-full max-w-2xl gap-4 sm:grid-cols-2">
    <Bars />
    <Bars showLabel={false} />
  </div>
);

export default Example;

Label formatter

labelFormatter writes ChartTooltipContent's heading, here a whole date, beside one that shows the point's label as it is by default.

import {
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  type ChartConfig,
} from "@produkto/ui/Chart";
import { Bar, BarChart, XAxis } from "recharts";

const data: { date: string; one: number }[] = [
  { date: "2026-11-02", one: 1840 },
  { date: "2026-11-03", one: 1625 },
  { date: "2026-11-04", one: 2210 },
];

const config = {
  one: { label: "Item 1", color: "var(--chart-3)" },
} satisfies ChartConfig;

const day = (label: unknown) =>
  new Date(String(label)).toLocaleDateString("en-GB", {
    weekday: "short",
    day: "numeric",
    month: "short",
    timeZone: "UTC",
  });

const Example = () => (
  <div className="grid w-full max-w-2xl gap-4 sm:grid-cols-2">
    <ChartContainer config={config}>
      <BarChart data={data} margin={{ top: 72 }}>
        <XAxis axisLine={false} dataKey="date" hide />
        <ChartTooltip
          content={<ChartTooltipContent />}
          defaultIndex={1}
          position={{ y: 0 }}
        />
        <Bar dataKey="one" fill="var(--color-one)" radius={4} />
      </BarChart>
    </ChartContainer>
    <ChartContainer config={config}>
      <BarChart data={data} margin={{ top: 72 }}>
        <XAxis axisLine={false} dataKey="date" hide />
        <ChartTooltip
          content={<ChartTooltipContent labelFormatter={day} />}
          defaultIndex={1}
          position={{ y: 0 }}
        />
        <Bar dataKey="one" fill="var(--color-one)" radius={4} />
      </BarChart>
    </ChartContainer>
  </div>
);

export default Example;

Name key

nameKey tells ChartTooltipContent and ChartLegendContent which field of a pie's rows names each slice in the config, beside a legend showing the raw names as it does by default.

import {
  ChartContainer,
  ChartLegend,
  ChartLegendContent,
  ChartTooltip,
  ChartTooltipContent,
  type ChartConfig,
} from "@produkto/ui/Chart";
import { Pie, PieChart } from "recharts";

const data: { category: string; value: number; fill: string }[] = [
  { category: "one", value: 1240, fill: "var(--color-one)" },
  { category: "two", value: 860, fill: "var(--color-two)" },
  { category: "three", value: 540, fill: "var(--color-three)" },
];

const config = {
  one: { label: "Item 1", color: "var(--chart-1)" },
  two: { label: "Item 2", color: "var(--chart-2)" },
  three: { label: "Item 3", color: "var(--chart-3)" },
} satisfies ChartConfig;

const Slices = ({ nameKey }: { nameKey?: string }) => (
  <ChartContainer config={config}>
    <PieChart>
      <ChartTooltip content={<ChartTooltipContent nameKey={nameKey} />} />
      <Pie data={data} dataKey="value" nameKey="category" />
      <ChartLegend content={<ChartLegendContent nameKey={nameKey} />} />
    </PieChart>
  </ChartContainer>
);

const Example = () => (
  <div className="grid w-full max-w-2xl gap-4 sm:grid-cols-2">
    <Slices />
    <Slices nameKey="category" />
  </div>
);

export default Example;

Legend

ChartLegend with ChartLegendContent lists the series under the chart, each with its colour and its label from the config.

import {
  ChartContainer,
  ChartLegend,
  ChartLegendContent,
  type ChartConfig,
} from "@produkto/ui/Chart";
import { Bar, BarChart, XAxis } from "recharts";

const data: { day: string; one: number; two: number }[] = [
  { day: "Thu", one: 28, two: 41 },
  { day: "Fri", one: 33, two: 57 },
  { day: "Sat", one: 46, two: 64 },
];

const config = {
  one: { label: "Item 1", color: "var(--chart-1)" },
  two: { label: "Item 2", color: "var(--chart-4)" },
} satisfies ChartConfig;

const Example = () => (
  <div className="w-full max-w-2xl">
    <ChartContainer config={config}>
      <BarChart data={data}>
        <XAxis axisLine={false} dataKey="day" tickLine={false} />
        <Bar dataKey="one" fill="var(--color-one)" radius={4} />
        <Bar dataKey="two" fill="var(--color-two)" radius={4} />
        <ChartLegend content={<ChartLegendContent />} />
      </BarChart>
    </ChartContainer>
  </div>
);

export default Example;

Show icon

showIcon, on by default, lets a series' icon in the config stand in for its swatch in the legend, as it does for its mark in the tooltip; showIcon false on ChartLegendContent keeps the swatch.

import {
  File01Icon,
  Folder01Icon,
  Image01Icon,
} from "@hugeicons/core-free-icons";
import {
  ChartContainer,
  ChartLegend,
  ChartLegendContent,
  type ChartConfig,
} from "@produkto/ui/Chart";
import { Bar, BarChart, XAxis } from "recharts";

const data: { month: string; one: number; two: number; three: number }[] = [
  { month: "Aug", one: 118, two: 46, three: 31 },
  { month: "Sep", one: 142, two: 41, three: 37 },
  { month: "Oct", one: 167, two: 38, three: 35 },
];

const config = {
  one: { label: "Item 1", icon: Folder01Icon, color: "var(--chart-4)" },
  two: { label: "Item 2", icon: File01Icon, color: "var(--chart-1)" },
  three: { label: "Item 3", icon: Image01Icon, color: "var(--chart-3)" },
} satisfies ChartConfig;

const Bars = ({ showIcon }: { showIcon?: boolean }) => (
  <ChartContainer config={config}>
    <BarChart data={data}>
      <XAxis axisLine={false} dataKey="month" tickLine={false} />
      <Bar dataKey="one" fill="var(--color-one)" radius={4} />
      <Bar dataKey="two" fill="var(--color-two)" radius={4} />
      <Bar dataKey="three" fill="var(--color-three)" radius={4} />
      <ChartLegend content={<ChartLegendContent showIcon={showIcon} />} />
    </BarChart>
  </ChartContainer>
);

const Example = () => (
  <div className="grid w-full max-w-2xl gap-4 sm:grid-cols-2">
    <Bars />
    <Bars showIcon={false} />
  </div>
);

export default Example;

API Reference

Chart

ChartProps · components/Chart/Chart.types.ts
PropTypeDefault
typeChartTrendType | "bars"("area" | "line") | "bars"-
dataChartPoint[] | ChartBar[]-
configChartConfig-
curveChartCurve"smooth" | "sharp"-
labelCountnumber-
sparklineboolean-
valueFormatter(value: TooltipValueType) => ReactNode-
initialDimension{ width: number; height: number }-
loadingboolean-
loadingIconboolean-

ChartContainer

ChartContainerProps · also takes the props of <div>
PropTypeDefault
configrequiredChartConfig-
childrenrequiredComponentProps<typeof ResponsiveContainer>["children"]-
initialDimension{ width: number; height: number }{ width: 320, height: 200 }

ChartTooltip

ChartTooltipProps · takes the props of recharts Tooltip

ChartTooltipContent

ChartTooltipContentProps
PropTypeDefault
classNamestring-
indicatorChartTooltipIndicator"dot" | "line" | "dashed" | "none""dot"
indicatorColorstring-
showLabelbooleantrue
nameKeystring-
valueFormatter(value: TooltipValueType) => ReactNode-

ChartLegend

ChartLegendProps · also takes the props of recharts Legend
PropTypeDefault
itemSorter-null

ChartLegendContent

ChartLegendContentProps · also takes the props of DefaultLegendContentProps
PropTypeDefault
classNamestring-
nameKeystring-
showIconbooleantrue
verticalAlignstring"bottom"

ChartPoint

used by data
PropTypeDefault
labelrequiredstring-
valuerequirednumber-
previousnumber | null-

ChartBar

used by data
PropTypeDefault
labelrequiredstring-
valuerequirednumber-
iconIconSvgElement-
mediaReactNode-