Components
Chart
Charts on Recharts in ink: series told apart by pattern, dash and label; one labelled image with a data table alternative; no animation under reduced motion.
Preview
A bar chart of stories filed and stories published for four desks. Politics leads on both. The table below gives every value.
Show the data as a table
| Desk | Filed | Published |
|---|---|---|
| Politics | 42 | 36 |
| Business | 37 | 31 |
| Culture | 19 | 18 |
| Science | 11 | 9 |
Install
bash
npx shadcn add @eloquent/chartThis adds recharts (Base UI has no chart) and the table item.
Usage
tsx
import { Bar, BarChart, CartesianGrid, Legend, Tooltip, XAxis, YAxis } from "recharts";
import { ChartContainer, ChartLegendContent, ChartTooltipContent } from "@/components/ui/chart";
const config = {
filed: { label: "Filed", pattern: "solid" },
published: { label: "Published", pattern: "hatch" },
};
<ChartContainer
config={config}
label="Stories filed and published, by desk"
caption="Stories filed and published this week, by desk."
data={rows}
categoryKey="desk"
table={{ summary: "Show the data as a table", categoryLabel: "Desk" }}
className="max-w-xl"
>
{(series) => (
<BarChart data={rows}>
<CartesianGrid vertical={false} />
<XAxis dataKey="desk" tickLine={false} />
<YAxis tickLine={false} width={32} />
<Tooltip cursor={false} content={<ChartTooltipContent />} />
<Legend content={<ChartLegendContent />} />
<Bar dataKey="filed" isAnimationActive={series.animate} {...series.bar("filed")} />
<Bar dataKey="published" isAnimationActive={series.animate} {...series.bar("published")} />
</BarChart>
)}
</ChartContainer>Use series.bar, series.line or series.area for each series: they return the ink fill or pattern, the outline and the dash. For a line chart pass variant="line" to ChartLegendContent and ChartTooltipContent. The component carries no English text: the chart name, caption, legend and table strings are props.
States
Show the data as a table
| Day | Web | App | |
|---|---|---|---|
| Mon | 120 | 80 | 40 |
| Tue | 118 | 96 | 52 |
| Wed | 125 | 110 | 61 |
| Thu | 121 | 134 | 70 |
| Fri | 130 | 150 | 88 |
Show the data as a table
| Day | Web | App |
|---|---|---|
| Mon | 80 | 40 |
| Tue | 96 | 52 |
| Wed | 110 | 61 |
| Thu | 134 | 70 |
| Fri | 150 | 88 |
| State | Treatment |
|---|---|
| Bars and areas | Ink fill or a hatch, dot, cross or line pattern, outlined in ink |
| Lines | Ink stroke; solid, dashed, dotted by series |
| Legend and tooltip | A swatch of the same pattern or dash, plus the series name |
| Data table | A disclosure with a 44px summary; opens to a ruled table of every value |
| Focus | 2px ink outline, 2px offset |
| Reduced motion | series.animate is false: the series draw at once |
Keyboard
| Key | Action |
|---|---|
| Tab | Moves to the "Show the data as a table" summary, then into the table's scroll region once open |
| Enter / Space | Opens or closes the data table (native details behaviour) |
The graphic is a single labelled image. The tooltip follows the pointer; every value it shows is in the table.
Vietnamese
Biểu đồ cột về số bài đã nộp và số bài đã đăng của bốn ban. Ban Chính trị dẫn đầu ở cả hai. Bảng bên dưới cho mọi giá trị.
Xem dữ liệu dạng bảng
| Ban | Đã nộp | Đã đăng |
|---|---|---|
| Chính trị | 42 | 36 |
| Kinh doanh | 37 | 31 |
| Văn hoá | 19 | 18 |
| Khoa học | 11 | 9 |
Ink adaptation
Upstream's hue-based chart colours become ink and patterns, so a chart reads in greyscale and in print. Series are named in the legend and the tooltip, never told apart by colour alone. The tooltip and legend lose their rounded, shadowed surfaces for a 1px ink rule. Recharts' own keyboard layer is off, and the data table is the keyboard and screen reader route.