Markdown Chart
Chart renderer for the markdown item, built on the shadcn/ui chart item. A chart fence carries a small JSON spec; bar, line, area and pie charts render once the fence closes and the spec validates, and the fence stays as source otherwise.
A `chart` fence carries one JSON object and renders through the shadcn/ui chart item: bar, line, area and pie, with tooltip and legend, colored from `--chart-*`. The fence stays as source until it closes and the spec validates; a spec that does not validate keeps the source and shows the reason. Bar, line and area values are finite numbers or `null` (a gap); a pie needs exactly one series, 1–12 slices with unique names and non-negative values. Charts render client-side because Recharts needs the measured width.
Preview
A chart fence carries a small JSON spec:
{
"type": "bar",
"title": "MRR by month",
"x": "month",
"series": [{ "key": "mrr", "label": "MRR" }],
"data": [{ "month": "Jan", "mrr": 120 }, { "month": "Feb", "mrr": 140 }]
}The fence stays as source until it closes and the spec validates.
Installation
Add the item with the shadcn CLI, or copy the source manually.
pnpm dlx shadcn@latest add litingyes/blocove/markdown-chartRequires a shadcn/ui project set up with Base UI primitives. Blocove is developed against the b0 preset, but it installs no base config or theme tokens: your own preset, fonts and colors stay in place.
Or install from the namespace after adding the registry: npx shadcn@latest add @blocove/markdown-chart
This example also uses: markdown
pnpm dlx shadcn@latest add litingyes/blocove/markdowntypeset.css next to your stylesheet, import it after Tailwind and add the .typeset-docs preset. See the Rich text editor setup.Usage
When a chart helps, answer with a chart fence whose body is one JSON object.Tell the model the fence language and this schema, or it will keep writing prose:
{ "type": "bar", "title": "MRR by month", "x": "month", "series": [{ "key": "mrr", "label": "MRR" }], "data": [{ "month": "Jan", "mrr": 120 }, { "month": "Feb", "mrr": 140 }]}
"type" is "bar", "line", "area" or "pie"; "x" is the category key;"series" lists the numeric keys with their labels; "data" holds the rows.A pie needs exactly one series, 1-12 rows and non-negative values.A bar or area chart can stack its series with "stacked": true.API Reference
Props accepted by the exported components.
MarkdownChart
The chart fence renderer. The shell passes `language`, `code`, `streaming` and `complete`; register it through `components.fences`. It renders the source until `complete` is set and the spec validates, then mounts the chart.
Extends MarkdownCodeProps.
| Prop | Type | Default |
|---|---|---|
language | string | Required |
code | string | Required |
streaming | boolean | - |
complete | boolean | - |
className | string | - |
MarkdownChartSpec
The JSON body of a `chart` fence, validated by `parseMarkdownChart` before anything renders.
| Prop | Type | Default |
|---|---|---|
type | 'bar' | 'line' | 'area' | 'pie' | Required |
title | string | - |
x | string | Required |
stacked | boolean | - |
series | MarkdownChartSeries[] | Required |
data | MarkdownChartRow[] | Required |