Every time a side project needs "a radar chart and a downloadable result image," the default reflex is to install Recharts (or Chart.js) plus html2canvas, maybe even spin up a serverless Puppeteer endpoint for crisp social cards. I have done that before, and I always regret it a week later. html2canvas chokes on Tailwind CSS variables, gradients shift subtly across Safari and Chrome, and suddenly a simple static page has a 200 KB JS tax or a cold-start API route just to render a PNG.
Recently I reviewed a much leaner pattern used inside a client-side 4-axis relationship health quiz that evaluates 20 items across four dimensions (Manipulation, Boundaries, Emotional Drain, and Psychological Safety). Both the live interactive radar chart and the downloadable 1080×1350 shareable card run with zero charting dependencies and zero DOM-to-image scraping.
Here is why the geometry is simpler than it looks. For an n-axis radar chart, every vertex is just polar-to-cartesian math starting at -Math.PI / 2 (12 o'clock):
const getPoint = (index: number, r: number, n: number, cx: number, cy: number) => {
const angle = -Math.PI / 2 + (index * 2 * Math.PI) / n;
return {
x: cx + Math.cos(angle) * r,
y: cy + Math.sin(angle) * r,
};
};
// Map 0-100 scores to SVG polygon points (clamped at 6 so zero scores remain visible)
const polygonPoints = axes
.map((a, i) => {
const p = getPoint(i, (radius * Math.max(a.score, 6)) / 100, axes.length, cx, cy);
return `${p.x.toFixed(1)},${p.y.toFixed(1)}`;
})
.join(' ');
That entire SVG component is roughly 110 lines of React. No ResizeObserver loops, no canvas hydration mismatches, and it renders crisply on Retina screens because it is vector by default.
For the downloadable PNG card, drawing directly onto an offscreen <canvas> (1080 × 1350) avoids every html2canvas quirk. The one gotcha you will hit if your app supports English, Japanese, and Chinese is line wrapping. text.split(' ') works for English and breaks immediately on CJK strings, overflowing right off the canvas edge. A tiny tokenizer switch solves it:
function wrapText(
ctx: CanvasRenderingContext2D,
text: string,
maxWidth: number,
maxLines: number
): string[] {
const isCJK = /[\u3040-\u30ff\u4e00-\u9fff]/.test(text);
const tokens = isCJK ? Array.from(text) : text.split(' ');
const lines: string[] = [];
let current = '';
for (const token of tokens) {
const candidate = current ? (isCJK ? current + token : `${current} ${token}`) : token;
if (ctx.measureText(candidate).width <= maxWidth) {
current = candidate;
} else {
if (current) lines.push(current);
current = token;
if (lines.length === maxLines - 1) break;
}
}
if (current && lines.length < maxLines) lines.push(current);
return lines;
}
Now for the honest trade-offs. Hand-rolled Canvas 2D code is verbose—a full styled card with rounded rectangles, progress bars, and disclaimers easily runs 400–500 lines of imperative drawing calls. If your layout changes every sprint or needs complex CSS flexbox alignment, Satori (@vercel/og) or Playwright screenshots will save you hours of manual pixel nudging. Also, relying on OS system font stacks (PingFang SC, Hiragino Sans, Inter) means the exported PNG will look slightly different on Windows vs. macOS unless you preload a custom FontFace.
When you only have a fixed card template and care about zero-backend privacy—especially for sensitive self-checks where users should not have to POST their answers to an image-generation server—skipping the heavy libraries is genuinely worth the extra Canvas boilerplate.
Top comments (1)
This is the right call for a quiz like this — the privacy angle is the real reason, not the bundle size. A relationship-health quiz that sent answers to a server for a screenshot would be a worse product, and your 110-line SVG plus the 1080×1350 offscreen canvas keeps the whole thing on the device. One thing the radar hides, though: 20 items across 4 dimensions means each vertex is the mean of 5 items, so a 3 on Boundaries could be five middling answers or a mix of 5s and 1s — very different stories. Have you considered drawing a faint min–max band behind each vertex so the spread shows, or is the single number the point for a quiz result?