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
Installation
Copies the component into components/ui and installs its dependencies and theme tokens.
pnpm dlx shadcn@latest add https://ui.tmih06.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. |
| labels | Partial<ChartCardLabels> | — | Your own UI strings (legend group, Total, screen-reader text), for translating. Right-to-left works under `dir="rtl"`; the plot still runs left to right. |
| 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.