Terminal
Installation
$ pnpm dlx shadcn@latest add @termcn/ink/dither-pie-chart
Usage
import {
Legend,
Pie,
PieChart,
Tooltip,
} from "@/components/ui/dither-pie-chart";
import type { ChartConfig } from "@/components/ui/dither-pie-chart";const data = [
{ channel: "direct", value: 42 },
{ channel: "search", value: 31 },
{ channel: "social", value: 17 },
];
const config = {
direct: { color: "blue", label: "Direct" },
search: { color: "green", label: "Search" },
social: { color: "pink", label: "Social" },
} satisfies ChartConfig;
<PieChart
config={config}
data={data}
dataKey="value"
innerRadius={0.42}
nameKey="channel"
width={46}
>
<Pie variant="gradient" />
<Legend align="left" />
<Tooltip />
</PieChart>;Examples
Textures and donut shapes
All four fill variants work for pies and donuts. Set innerRadius between 0 and 0.92 to open the center.
Terminal
API Reference
| Prop | Type | Default |
|---|---|---|
data | TData[] | required |
config | ChartConfig | required |
dataKey | string | required |
nameKey | string | required |
innerRadius | number from 0 to 0.92 | 0 |
width | number | 56 |
height | number | 12 |
markerIndex | number | null | null |
noColor | boolean | false |
screenReaderMode | boolean | false |
Use left/right to inspect slices and up/down to focus legend entries.
Notes
Accessibility
termcn exposes the following behavior through Ink's terminal accessibility APIs. This is not a browser ARIA or general WCAG-conformance claim.
- Keyboard: Arrow keys or
h/j/k/lmove through the chart;Enter/Spaceselect a point;Escapeclears the active point;rrestarts enabled animation. - Focus and composition: Input is active only while the component's focus target is focused, enabled, active, and inside the topmost focus scope.
- Screen reader: Visual output exposes its meaningful value through a textual alternative or bounded accessible summary.