Reference index

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.

Stories filed and published this week, by desk.
Show the data as a table
Stories filed and published, by desk
DeskFiledPublished
Politics4236
Business3731
Culture1918
Science119

Install

bash

npx shadcn add @eloquent/chart

This 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

Lines: solid, dashed and dotted, named in the legend.
Show the data as a table
Readers by channel, line chart
DayPrintWebApp
Mon1208040
Tue1189652
Wed12511061
Thu12113470
Fri13015088
Areas: hatched and dotted, outlined in ink.
Show the data as a table
Readers on the web and the app, area chart
DayWebApp
Mon8040
Tue9652
Wed11061
Thu13470
Fri15088
StateTreatment
Bars and areasInk fill or a hatch, dot, cross or line pattern, outlined in ink
LinesInk stroke; solid, dashed, dotted by series
Legend and tooltipA swatch of the same pattern or dash, plus the series name
Data tableA disclosure with a 44px summary; opens to a ruled table of every value
Focus2px ink outline, 2px offset
Reduced motionseries.animate is false: the series draw at once

Keyboard

KeyAction
TabMoves to the "Show the data as a table" summary, then into the table's scroll region once open
Enter / SpaceOpens 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ị.

Số bài đã nộp và đã đăng trong tuần, theo ban.
Xem dữ liệu dạng bảng
Số bài đã nộp và đã đăng, theo ban
BanĐã nộpĐã đăng
Chính trị4236
Kinh doanh3731
Văn hoá1918
Khoa học119

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.