PortalJS — Add Chart
Overview
Add a visualization to a dataset's showcase in a PortalJS portal. The skill installs
recharts (added directly — never @portaljs/components), writes a reusable client-side
Chart component into components/, and renders a <Chart /> into the Views section
of the showcase route pages/[owner]/[slug].tsx for one chosen dataset. The chart reads the
same /public/data/<file> the showcase <Table /> already uses, so no data is duplicated.
Five chart types are supported: line, bar, area, pie, and scatter.
Prerequisites
- A scaffolded PortalJS portal (see
portaljs-new-portal).
- The target dataset already registered in
datasets.json (see portaljs-add-dataset).
components/ui/parseCsv.ts present (ships with the template).
- Node 18+ and npm available in the portal directory.
Instructions
The canonical, full step-by-step workflow is
.claude/commands/portaljs-add-chart.md —
the single source of truth. Read and follow it when executing. Summary:
- Gather input — dataset slug, X column, Y column(s), chart type (default
line), portal
directory. If any is missing, interview the user; never dead-end on a missing value.
- Resolve the dataset from
datasets.json (namespace, file, format).
- Validate that the X and every Y column exist in the data file's header; warn on
non-numeric Y columns (values are coerced with
Number()).
- Install the chart library:
npm install recharts@^2.15.0.
- Write
components/Chart.tsx (idempotent — do not overwrite a customized component).
- Render
<Chart /> into the Views section, gated on the dataset's (namespace, slug) so
other showcases are unaffected. Extend an existing view-dispatch block, do not overwrite.
- Verify with
npx tsc --noEmit.
- Report the component, route, and dependency added.
Output
- Created:
components/Chart.tsx (recharts wrapper, if absent).
- Modified:
pages/[owner]/[slug].tsx (import + gated <Chart /> in Views);
package.json (recharts@^2.15.0).
- Verified:
npx tsc --noEmit passes.
- Result: the chart renders at
/@<namespace>/<slug> under a "Views" heading.
Error Handling
| Symptom |
Cause |
Fix |
| Missing dataset/columns |
Slug or column not in manifest/header |
List available slugs/headers and re-prompt; do not error out. |
| Gaps in the chart |
Non-numeric cells coerced to NaN |
Clean the source data or pick a numeric Y column. |
tsc failure |
Bad column prop or import path |
Fix the first reported error before reporting success. |
| Sluggish render |
Over ~2,000 SVG points |
Pre-aggregate the series (e.g. yearly buckets). |
Examples
Example 1 — Single line series
/portaljs-add-chart co2-emissions x=year y=emissions type=line
Example 2 — Multi-series bar chart
/portaljs-add-chart trade x=year y=imports,exports type=bar
Example 3 — Pie chart of a categorical breakdown
/portaljs-add-chart budget x=department y=amount type=pie
Resources
Source: jeremylongshore/claude-code-plugins-plus-skills → plugins/community/portaljs/skills/portaljs-add-chart/SKILL.md
1---2name: portaljs-add-chart3description: Add a chart (line, bar, area, pie, or scatter) to a dataset's showcase in a PortalJS portal. Installs recharts, writes a reusable Chart component, and renders it in the showcase Views section. Use when visualizing a dataset already registered in datasets.json.4---567# PortalJS — Add Chart89## Overview1011Add a visualization to a dataset's **showcase** in a PortalJS portal. The skill installs12`recharts` (added directly — never `@portaljs/components`), writes a reusable client-side13`Chart` component into `components/`, and renders a `<Chart />` into the **Views** section14of the showcase route `pages/[owner]/[slug].tsx` for one chosen dataset. The chart reads the15same `/public/data/<file>` the showcase `<Table />` already uses, so no data is duplicated.16Five chart types are supported: line, bar, area, pie, and scatter.1718## Prerequisites1920- A scaffolded PortalJS portal (see `portaljs-new-portal`).21- The target dataset already registered in `datasets.json` (see `portaljs-add-dataset`).22- `components/ui/parseCsv.ts` present (ships with the template).23- Node 18+ and npm available in the portal directory.2425## Instructions2627The canonical, full step-by-step workflow is28[`.claude/commands/portaljs-add-chart.md`](https://github.com/datopian/portaljs/blob/main/.claude/commands/portaljs-add-chart.md) —29the single source of truth. Read and follow it when executing. Summary:30311. Gather input — dataset slug, X column, Y column(s), chart type (default `line`), portal32 directory. If any is missing, interview the user; never dead-end on a missing value.332. Resolve the dataset from `datasets.json` (`namespace`, `file`, `format`).343. Validate that the X and every Y column exist in the data file's header; warn on35 non-numeric Y columns (values are coerced with `Number()`).364. Install the chart library: `npm install recharts@^2.15.0`.375. Write `components/Chart.tsx` (idempotent — do not overwrite a customized component).386. Render `<Chart />` into the Views section, gated on the dataset's `(namespace, slug)` so39 other showcases are unaffected. Extend an existing view-dispatch block, do not overwrite.407. Verify with `npx tsc --noEmit`.418. Report the component, route, and dependency added.4243## Output4445- **Created:** `components/Chart.tsx` (recharts wrapper, if absent).46- **Modified:** `pages/[owner]/[slug].tsx` (import + gated `<Chart />` in Views);47 `package.json` (`recharts@^2.15.0`).48- **Verified:** `npx tsc --noEmit` passes.49- **Result:** the chart renders at `/@<namespace>/<slug>` under a "Views" heading.5051## Error Handling5253| Symptom | Cause | Fix |54| --- | --- | --- |55| Missing dataset/columns | Slug or column not in manifest/header | List available slugs/headers and re-prompt; do not error out. |56| Gaps in the chart | Non-numeric cells coerced to `NaN` | Clean the source data or pick a numeric Y column. |57| `tsc` failure | Bad column prop or import path | Fix the first reported error before reporting success. |58| Sluggish render | Over ~2,000 SVG points | Pre-aggregate the series (e.g. yearly buckets). |5960## Examples6162### Example 1 — Single line series6364```65/portaljs-add-chart co2-emissions x=year y=emissions type=line66```6768### Example 2 — Multi-series bar chart6970```71/portaljs-add-chart trade x=year y=imports,exports type=bar72```7374### Example 3 — Pie chart of a categorical breakdown7576```77/portaljs-add-chart budget x=department y=amount type=pie78```7980## Resources8182- Full workflow: [`.claude/commands/portaljs-add-chart.md`](https://github.com/datopian/portaljs/blob/main/.claude/commands/portaljs-add-chart.md)83- Chart-type and prop reference: [`references/reference.md`](references/reference.md)84- Related skills: `portaljs-add-dataset`, `portaljs-add-map`, `portaljs-define-schema`85- recharts documentation: <https://recharts.org/>8687---8889**Source:** [`jeremylongshore/claude-code-plugins-plus-skills`](https://github.com/jeremylongshore/claude-code-plugins-plus-skills) → `plugins/community/portaljs/skills/portaljs-add-chart/SKILL.md`