# 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. ## Installation ```bash npx shadcn@latest add litingyes/blocove/markdown-chart ``` > Typography requires [shadcn/typeset](https://ui.shadcn.com/docs/typeset). Copy `typeset.css` next to your main stylesheet, import it after Tailwind and add the `.typeset-docs` preset. This example also uses: `markdown`. ```bash npx shadcn@latest add litingyes/blocove/markdown ``` 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. ## Usage ### Model contract ```text 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 ### 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` | ## Registry dependencies - `litingyes/blocove/markdown-parse` - `chart` - `code-block` Namespace: `npx shadcn@latest add @blocove/markdown-chart`