Radar chart
Compare named profiles on a shared web with per-axis maxima, profile visibility controls and a native axis reader.
pnpm dlx shadcn@latest add @haze/radar-chart---
import { ChevronDown } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";
interface Axis{key:string;label:string;max?:number}
interface Profile{label:string;values:Record<string,number>}
interface Props{label?:string;axes?:Axis[];profiles?:Profile[];max?:number;class?:string}
const{label="Workspace profiles",max=100,axes=[{key:"speed",label:"Speed"},{key:"quality",label:"Quality"},{key:"clarity",label:"Clarity"},{key:"coverage",label:"Coverage"},{key:"cost",label:"Efficiency"}],profiles=[{label:"Current",values:{speed:72,quality:84,clarity:68,coverage:75,cost:86}},{label:"Proposed",values:{speed:88,quality:78,clarity:90,coverage:82,cost:64}}],class:className}=Astro.props;
const keys=new Set<string>(),dimensions=axes.filter(axis=>{if(!axis.key||keys.has(axis.key))return false;keys.add(axis.key);return true;}).map(axis=>({...axis,max:Number.isFinite(axis.max)&&axis.max!>0?axis.max!:(Number.isFinite(max)&&max>0?max:100)}));
const rows=profiles.map(profile=>({...profile,values:dimensions.map(axis=>Number.isFinite(profile.values[axis.key])?Math.max(0,Math.min(axis.max,profile.values[axis.key])):null)}));
const xy=(index:number,radius:number)=>[150+Math.sin(index/dimensions.length*Math.PI*2)*radius,150-Math.cos(index/dimensions.length*Math.PI*2)*radius];
const polygons=rows.map(row=>row.values.every(value=>value!==null)?row.values.map((value,index)=>xy(index,(value??0)/dimensions[index].max*80).join(",")).join(" "):"");
const colors=["stroke-brand fill-brand/10 bg-brand","stroke-success fill-success/10 bg-success","stroke-warning fill-warning/10 bg-warning","stroke-muted-foreground fill-muted-foreground/10 bg-muted-foreground"];
const grid=[.25,.5,.75,1].map(ratio=>dimensions.map((_,index)=>xy(index,ratio*80).join(",")).join(" "));
---
<figure data-haze-radar-chart data-axes={JSON.stringify(dimensions)} data-profiles={JSON.stringify(rows)} class={cn("grid min-w-0 gap-3 rounded-xl border border-border bg-card p-4.5 text-card-foreground",className)}>
<figcaption class="text-[0.9375rem]/5 font-medium tracking-[-0.01em] wrap-anywhere">{label}</figcaption>
{dimensions.length>=3&&rows.length?<svg aria-hidden="true" viewBox="0 14 300 266" class="mx-auto aspect-[300/266] w-full max-w-96">
{grid.map(points=><polygon points={points} fill="none" class="stroke-border"/>)}
{dimensions.map((axis,index)=>{const end=xy(index,80),text=xy(index,114);return <g><path d={"M150 150L"+end.join(" ")} class="stroke-border"/><text x={text[0]} y={text[1]} text-anchor="middle" dominant-baseline="middle" class="fill-muted-foreground text-[16px] sm:text-[13px]">{axis.label.length>12?axis.label.slice(0,11)+"…":axis.label}</text></g>;})}
{polygons.map((points,index)=>points&&<polygon data-radar-profile={index} points={points} stroke-width="2" stroke-dasharray={index%2?"5 3":undefined} class={cn("transition-opacity duration-200 ease-snappy data-[dimmed]:opacity-15",colors[index%colors.length])}/>)}
<path data-radar-spoke d={"M150 150L"+xy(0,80).join(" ")} stroke-width="2" class="stroke-foreground"/>
</svg>:<p class="text-sm/6 text-muted-foreground">Provide at least three axes and a profile to compare.</p>}
<div class="flex min-w-0 flex-wrap gap-1">{rows.map((row,index)=><button data-radar-toggle={index} type="button" aria-pressed="true" disabled class="group flex min-h-8 max-w-full items-center gap-2 rounded-lg px-2 text-xs/5 transition-colors duration-150 ease-snappy enabled:hover:bg-accent focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring"><span aria-hidden="true" class={cn("size-2 shrink-0 rounded-full",colors[index%colors.length])}></span><span class="wrap-anywhere group-aria-[pressed=false]:line-through">{row.label}</span></button>)}</div>
{dimensions.length>=3&&<label data-radar-control hidden class="grid gap-1 text-xs/5 text-muted-foreground">Compare an axis<input data-radar-cursor aria-label="Axis to compare" type="range" min="0" max={dimensions.length-1} value="0" step="1" class="h-10 w-full min-w-0 cursor-pointer appearance-none rounded-md bg-transparent focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring disabled:cursor-not-allowed [&::-webkit-slider-runnable-track]:h-1.5 [&::-webkit-slider-runnable-track]:rounded-full [&::-webkit-slider-runnable-track]:bg-input [&::-webkit-slider-thumb]:-mt-2 [&::-webkit-slider-thumb]:size-5.5 [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:border-0 [&::-webkit-slider-thumb]:bg-foreground [&::-webkit-slider-thumb]:shadow-key [&::-webkit-slider-thumb]:transition-[scale] [&::-webkit-slider-thumb]:duration-150 [&::-webkit-slider-thumb]:ease-snappy enabled:active:[&::-webkit-slider-thumb]:scale-95 [&::-moz-range-track]:h-1.5 [&::-moz-range-track]:rounded-full [&::-moz-range-track]:bg-input [&::-moz-range-thumb]:size-5.5 [&::-moz-range-thumb]:rounded-full [&::-moz-range-thumb]:border-0 [&::-moz-range-thumb]:bg-foreground [&::-moz-range-thumb]:shadow-key [&::-moz-range-thumb]:transition-[scale] [&::-moz-range-thumb]:duration-150 [&::-moz-range-thumb]:ease-snappy enabled:active:[&::-moz-range-thumb]:scale-95 forced-colors:appearance-auto"/></label>}
<p data-radar-readout role="status" aria-live="polite" class="min-h-10 text-xs/5 text-muted-foreground">Values share the documented maximum of each axis. Missing values leave a profile undrawn.</p>
<details class="group min-w-0 border-t border-border pt-3"><summary class="flex min-h-7 cursor-pointer list-none items-center justify-between gap-2 rounded-sm text-[0.8125rem]/5 font-medium text-muted-foreground transition-colors duration-150 ease-snappy hover:text-foreground focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring [&::-webkit-details-marker]:hidden">Profile measurements<ChevronDown aria-hidden="true" class="size-3.5 shrink-0 transition-[rotate] duration-200 ease-snappy group-open:rotate-180" /></summary><table class="mt-3 w-full table-fixed text-left text-xs/5"><caption class="sr-only">{label}</caption><thead><tr><th scope="col" class="p-1">Measure</th><th scope="col" class="p-1">Profile values</th></tr></thead><tbody>{dimensions.map((axis,index)=><tr class="border-t border-border"><th scope="row" class="p-1 font-normal wrap-anywhere">{axis.label} / {axis.max}</th><td class="p-1 tabular-nums wrap-anywhere">{rows.map(row=>row.label+": "+(row.values[index]??"No value")).join("; ")}</td></tr>)}</tbody></table></details>
</figure>
<script>
function initRadar(){document.querySelectorAll<HTMLElement>("[data-haze-radar-chart]:not([data-enhanced])").forEach(root=>{
root.dataset.enhanced="";const axes:{label:string;max:number}[]=JSON.parse(root.dataset.axes||"[]"),profiles:{label:string;values:(number|null)[]}[]=JSON.parse(root.dataset.profiles||"[]"),shown=profiles.map(()=>true),buttons=Array.from(root.querySelectorAll<HTMLButtonElement>("[data-radar-toggle]")),polygons=root.querySelectorAll<SVGPolygonElement>("[data-radar-profile]"),cursor=root.querySelector<HTMLInputElement>("[data-radar-cursor]"),spoke=root.querySelector<SVGPathElement>("[data-radar-spoke]");
const read=()=>{const index=Number(cursor?.value||0),axis=axes[index];if(!axis)return;const text=axis.label+" (maximum "+axis.max+"): "+profiles.filter((_,i)=>shown[i]).map(row=>row.label+" "+(row.values[index]??"no value")).join("; ");root.querySelector("[data-radar-readout]")!.textContent=text;cursor?.setAttribute("aria-valuetext",text);spoke?.setAttribute("d","M150 150L"+(150+Math.sin(index/axes.length*Math.PI*2)*80)+" "+(150-Math.cos(index/axes.length*Math.PI*2)*80));};
buttons.forEach((button,index)=>{button.disabled=false;button.addEventListener("click",()=>{if(shown[index]&&shown.filter(Boolean).length===1){root.querySelector("[data-radar-readout]")!.textContent="Keep one profile visible.";return;}shown[index]=!shown[index];button.setAttribute("aria-pressed",String(shown[index]));polygons.forEach(p=>p.toggleAttribute("data-dimmed",!shown[Number(p.dataset.radarProfile)]));read();});});root.querySelector("[data-radar-control]")?.removeAttribute("hidden");cursor?.addEventListener("input",read);read();
});}
initRadar();if(!document.documentElement.hasAttribute("data-haze-radar-chart-listener")){document.documentElement.setAttribute("data-haze-radar-chart-listener","");document.addEventListener("astro:page-load",initRadar);}
</script>When to use
- A few profiles share at least three bounded dimensions.
- The shape of strengths and gaps matters more than precise ranking.
When not to use
- Category magnitudes should be compared on a straight baseline. Use bar-chart.
Installation
Add the Haze registry to components.json once, then install Radar chart with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/radar-chartnpx shadcn@latest add @haze/radar-chartyarn dlx shadcn@latest add @haze/radar-chartbunx --bun shadcn@latest add @haze/radar-chartFirst time? Registry and theme setup
1. Add to components.json:
{
"registries": {
"@haze": "http://localhost:4329/r/{name}.json"
}
}2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| label | string | Workspace profiles | Figure and table caption. |
| axes | { key: string; label: string; max?: number }[] | – | At least three uniquely keyed axes; optional positive maxima override the global maximum. |
| profiles | { label: string; values: Record<string, number> }[] | – | Values clamp to each axis range; missing or nonfinite values leave the profile undrawn. |
| max | number | 100 | Fallback upper bound for all axes. |
| class | string | – | Additional classes on the chart figure. |
Keyboard interactions
- Arrow keysHomeEnd
- Select the axis whose profile values are read.
- EnterSpace
- Toggle a profile while keeping at least one profile visible.
Accessibility
- The native axis range reads each visible profile's value and the axis maximum; the decorative SVG claims no interactive role.
- Profiles with missing measurements stay undrawn and retain their missing-value text in the accessible table.
Notes for AI
Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.
Install and use
Install the Haze UI component "Radar chart" with `npx shadcn@latest add @haze/radar-chart`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import RadarChart from "@/components/haze/ui/radar-chart.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/radar-chart.md
Customize with real content
Adapt the Haze radar-chart ui for our product. Replace the demo values of these props with our real content: label, axes, profiles, max, class. Keep the layout, the heading level rules and these accessibility details: The native axis range reads each visible profile's value and the axis maximum; the decorative SVG claims no interactive role. Profiles with missing measurements stay undrawn and retain their missing-value text in the accessible table. Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using radar-chart, check it fits: use it when a few profiles share at least three bounded dimensions.; the shape of strengths and gaps matters more than precise ranking.. Avoid it when category magnitudes should be compared on a straight baseline. use bar-chart.. Alternatives: @haze/bar-chart, @haze/slope-chart, @haze/table.
Dependencies
- npm: @lucide/astro
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.