Chart
Renders interactive charts in the browser using Chart.js from context-supplied data and chart type.
Workflow
- Extract data and chart type — identify labels, datasets, and chart type (bar, line, pie, doughnut, radar) from the user's request or conversation context.
- Choose colors — assign dataset colors from the standard palette. See TEMPLATE.md for the palette.
- Write the HTML file — write a complete self-contained file to
/tmp/chart.htmlusing the Chart.js template matching the chart type. See TEMPLATE.md for all templates. - Render in browser — follow
_shared/chrome-devtools-render.mdto open/tmp/chart.html, wait for render, screenshot, and fix-and-reload if needed.wait_forthe static<h2 id="ready">text (Chart.js renders to canvas — canvas text is NOT detectable bywait_for). See TROUBLESHOOTING.md for chart-specific fixes.
Self-review checklist
Before delivering, verify ALL:
- Screenshot shows the chart with visible title, labels, and data — no blank canvas
- Chart text is readable on dark background — not invisible black-on-dark
- Container div has explicit
height(e.g.500px) in CSS — not just on the canvas element - Both
responsive: trueandmaintainAspectRatio: falseare set in chart options -
Chart.defaults.colorandChart.defaults.borderColorare set beforenew Chart() - Dataset colors are from the standard palette — no ad-hoc inline colors
- CDN URL is exactly
https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.4.1/chart.umd.min.js -
wait_foris called with the chart title text beforetake_screenshot
Golden rules
Hard rules. Never violate these.
- Never set width or height on the canvas element. Set dimensions on the wrapper div via CSS (
height: 500px). Canvas attributes override Chart.js responsive sizing. - Always set both
responsive: trueandmaintainAspectRatio: false. Either alone is insufficient — the chart collapses to 0 height without both. - Always set
Chart.defaults.colorandChart.defaults.borderColorbefore creating any chart. Without them, all text renders as black and is invisible on the dark background. - Always use
new_pagefor first open. Usemcp__chrome-devtools__new_pagewithurl: file:///tmp/chart.html. Usenavigate_pagewithtype: reloadonly for subsequent fixes. - Always add a static
<h2 id="ready">Title</h2>above the canvas andwait_forit. Chart.js renders text onto canvas — canvas text is invisible towait_for. The static element is the only reliable render signal. - Never hardcode colors inline in datasets. Always use colors from the standard palette array defined in TEMPLATE.md.
Reference files
| File | Contents |
|---|---|
| TEMPLATE.md | Complete Chart.js HTML templates for bar, line, and pie/doughnut; color palette; data format patterns |
| TROUBLESHOOTING.md | Failure diagnosis table: symptoms, causes, fixes |