Interactive Answers
Chart Card
A chart the agent answers with — bar, line, area or donut, with tooltips, legend toggles and animated data.
4 variantsMIT
Preview
Weekly signups
Self-serve vs. sales-led · last 8 weeks
4,987
| Label | Self-serve | Sales-led |
|---|---|---|
| Sep 8 | 412 | 96 |
| Sep 15 | 468 | 104 |
| Sep 22 | 431 | 88 |
| Sep 29 | 520 | 131 |
| Oct 6 | 588 | 120 |
| Oct 13 | 610 | 142 |
| Oct 20 | 654 | 150 |
| Oct 27 | 402 | 71 |
Installation
Copies the component into components/ui and installs its dependencies and theme tokens.
pnpm dlx shadcn@latest add https://tuffui.com/r/chart-card.jsonUsage
Pass your own data and wire the callbacks to your agent runtime.
import { ChartCard } from "@/components/ui/chart-card";
// Render a chart when a tool returns a time series.
export function SignupsAnswer({ result }: { result: SignupsResult }) {
return (
<ChartCard
type="bar"
title="Weekly signups"
subtitle="Self-serve vs. sales-led"
total={result.total.toLocaleString()}
partialLast // the current week isn't over
data={{
labels: result.weeks,
series: [
{ id: "self", label: "Self-serve", values: result.selfServe },
{ id: "sales", label: "Sales-led", values: result.salesLed },
],
}}
onSelect={(index) => console.log(result.weeks[index])}
/>
);
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
| data* | { labels: string[]; series: ChartSeries[] } | — | One label per point and up to four series. Series keep their color when others are toggled off. |
| type | "bar" | "line" | "area" | "donut" | "bar" | Grouped bars, lines, filled areas, or a donut where each series is one slice. |
| title* | string | — | Header title, also the chart's accessible name. |
| subtitle | string | — | Secondary line under the title. |
| total | string | — | Headline value in the header; rolls when it changes. |
| format | (value: number) => string | — | Formats axis ticks, tooltip values and the donut center. Defaults to 1.2k / 3.4M. |
| partialLast | boolean | false | Stripes the last bar, for a period that is still in progress. |
| onSelect | (index: number) => void | — | Called when a point or slice is hovered, clicked or reached with the arrow keys. |
| className | string | — | Extra classes for the root element. |
type ChartSeries = {
id: string;
label: string;
values: number[]; // one per label; a donut slice is their sum
color?: string; // defaults to blue, teal, purple, ochre by position
};
// Keyboard: focus the chart, then ← → Home End move between points, Esc clears.
// Screen readers get a summary label and a hidden data table.