Radar charts in pure CSS: porting st-core spider charts into ProvChart

2026-11-24来源 dev.toEnglish
Radar charts in pure CSS: porting st-core spider charts into ProvChart

Spider (radar) charts are the one chart type I kept getting asked for and kept skipping. The usual answer is a chart library, which is exactly the thing ProvChart exists to avoid.

But I already had. st-core.fscss has spider charts built in pure CSS, so this release is that idea, adapted to ProvChart's pipeline: JSON in, HTML/CSS or SVG out, no chart library on the page.

A two-series radar chart on a dark theme

What shipped

  • type: "radar" (alias spider) in the HTML/CSS engine, the SVG engine, and both API endpoints
  • Radar in the Pro Dashboard (Chart Builder and SVG Export tabs)
  • radar and gridShape in the MCP server (provchart-mcp 1.1.0)
  • Per-vertex tooltips in provchart-runtime 1.2.1

Using it

One value per axis, at least three axes. axisX names the axes.

{ "type": "radar", "theme": "midnight", "axisX": ["Speed", "Quality", "UX", "Scale", "Cost", "Support"], "series": [ { "name": "Team A", "color": "#8b7bff", "points": [92, 78, 85, 55, 48, 80] }, { "name": "Team B", "color": "#4fd8c4", "points": [68, 82, 70, 95, 62, 58] } ] } 

For a README, ask for SVG and commit the file:

curl -s -X POST "https://provchart-api.devtem.org/api/v1/generate-svg" \ -H "Content-Type: application/json" \ -H "X-API-Key: YOUR_API_KEY" \ -d '{"type":"radar","width":420,"height":420,"axisX":["A","B","C","D","E"],"series":[{"name":"S","points":[60,80,40,90,70]}]}' 

For a web page, call /api/v1/generate from your server and inject the returned html and css.

Option What it does
gridShape circle (default) or polygon rings
grid: { rows: 5 } Number of rings (default 4)
axisY: false Hide the ring values
min / max Fix the scale

If you leave max out, the outer ring rounds up to a clean step. A data peak of 92 gives rings at 25, 50, 75 and 100 instead of 23, 46, 69 and 92.

ProvChart polygon shape radar chart

How the CSS version works

The browser never does trig. I compute every vertex at generation time and write it into CSS custom properties as plain percentages:

x = 50% + r * sin(angle) y = 50% - r * cos(angle) 

Axis 0 points up and the rest run clockwise. The fill is a clip-path: polygon() that reads those variables, so updating a chart is just rewriting variables, same as the line and area charts.

The part I liked most is the outline. There is no stroke in clip-path, so the line is the same polygon minus a copy of itself nudged toward the center by 2px, using the evenodd fill rule:

clip-path: polygon(evenodd, /* outer vertices */, /* inner vertices */); 

The spokes are plain 1px lines rotated into place, so they always sit exactly on the axes. The circle grid is a radial-gradient with closest-side sizing, so ring radii match the data scale.

Things to know

  • A series needs at least 3 points, otherwise the API returns a 400 with the reason.
  • The HTML/CSS version uses modern CSS (color-mix(), aspect-ratio, evenodd clip paths). The SVG output works anywhere.
  • Radar is a Pro chart type.
  • The optional runtime adds hover tooltips on each vertex (axis name, series, real value). Painting never depends on it.

Links

If a radar renders oddly with your data, open an issue and include the payload. That is the fastest way for me to fix it.

原文:https://www.a8q9.cn/en/article/radar-charts-in-pure-css-porting-st-core-spider-charts-into-provchart-912128.html

相关文章