# Comparative Polygon Spider Radar Overlay

> Multi-entity polygon radar overlay evaluating performance dimensions.

A shadcn/ui block from the [@paceui](https://paceui.com/?utm_source=shadcn.exchange) registry, listed on [shadcn.exchange](https://shadcn.exchange/r/paceui/tanstack-charts-comparative-radar).

- Page, with a live preview: https://shadcn.exchange/r/paceui/tanstack-charts-comparative-radar
- Screenshot: https://abzjhwgwpdpz7ua5.public.blob.vercel-storage.com/shots/paceui/tanstack-charts-comparative-radar-light-51d7d819ae4c5023.png
- Registry item: https://paceui.com/r/tanstack-charts-comparative-radar.json
- Listed: 2026-10-21, source last changed 2026-10-21

## Install

```bash
npx shadcn@latest add https://shadcn.exchange/r/paceui/tanstack-charts-comparative-radar.json
```

Run it in a project that has shadcn/ui set up. It adds the files below and installs what they depend on.

## Dependencies

- npm packages: `@tanstack/charts`, `@tanstack/react-charts`, `d3-scale`, `d3-shape`
- Registry items: `card`

## Files

### `components/tanstack-charts/pie/comparative-radar.tsx`

```tsx
import { type ChartPoint, defineChart } from "@tanstack/charts";
import { motion } from "@tanstack/charts/motion";
import { angleGrid, polar, radialArea, radialGrid } from "@tanstack/charts/polar";
import { tooltip } from "@tanstack/charts/tooltip";
import { Chart } from "@tanstack/react-charts/core";
import { useMemo } from "react";

import { scaleLinear, scalePoint } from "d3-scale";
import { curveLinearClosed } from "d3-shape";
import { ShieldAlert } from "lucide-react";

import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card";

interface RadarScoreDatum {
    entity: string;
    attribute: string;
    score: number;
}

const motionRenderer = motion({
    initial: "always",
    transition: { type: "spring", stiffness: 170, damping: 18, mass: 1 },
});

const attributes = ["Speed", "Reliability", "Security", "Scalability", "Usability"];
const entities = ["Product A", "Product B"];
const colors = ["var(--chart-1)", "var(--chart-2)"];
const ringValues = [0.2, 0.4, 0.6, 0.8, 1];

function generateDemoData(): RadarScoreDatum[] {
    const results: RadarScoreDatum[] = [];
    const scoresA = [0.85, 0.9, 0.95, 0.7, 0.8];
    const scoresB = [0.65, 0.75, 0.8, 0.95, 0.9];

    attributes.forEach((attr, idx) => {
        results.push({ entity: "Product A", attribute: attr, score: scoresA[idx] });
        results.push({ entity: "Product B", attribute: attr, score: scoresB[idx] });
    });

    return results;
}

function shadcnTooltipContent<TDatum>(points: readonly ChartPoint<TDatum>[]) {
    if (points.length === 0) return { title: "", rows: [] };
    const d = points[0].datum as RadarScoreDatum;
    if (!d) return { title: "", rows: [] };
    return {
        title: `${d.entity} - ${d.attribute}`,
        rows: [{ label: "Performance Score", value: `${Math.round(d.score * 100)}%`, color: "var(--chart-1)" }],
    };
}

export function ComparativeRadar() {
    const data = useMemo(() => generateDemoData(), []);

    const definition = useMemo(
        () =>
            defineChart(
                {
                    renderer: motionRenderer,
                    scales: {
                        x: null,
                        y: null,
                    },
                    marks: [
                        polar({
                            scales: {
                                angle: { scale: scalePoint<string>().domain(attributes), wrap: true },
                                radius: { scale: scaleLinear().domain([0, 1]) },
                            },
                            inset: 0,
                            radiusRatio: 0.75,
                            guides: [
                                radialGrid({
                                    values: ringValues,
                                    shape: "polygon",
                                    labels: true,
                                    labelAngle: Math.PI / 4,
                                    format: (v) => `${Number(v) * 100}%`,
                                    labelFill: "var(--muted-foreground)",
                                    stroke: "var(--border)",
                                }),
                                angleGrid({
                                    values: attributes,
                                    labels: true,
                                    labelOffset: 8,
                                    labelFill: "var(--foreground)",
                                    labelFontSize: 11,
                                    format: String,
                                    stroke: "var(--border)",
                                }),
                            ],
                            marks: [
                                radialArea(data, {
                                    id: "country-profiles",
                                    angle: "attribute",
                                    radius: "score",
                                    color: "entity",
                                    key: ({ entity, attribute }) => `${entity}:${attribute}`,
                                    curve: curveLinearClosed,
                                    fillOpacity: 0.2,
                                }),
                            ],
                        }),
                    ],
                    color: {
                        domain: entities,
                        range: colors,
                    },
                    margin: { top: 20, right: 20, bottom: 20, left: 20 },
                    theme: {
                        foreground: "var(--muted-foreground)",
                        grid: "var(--border)",
                        background: "transparent",
                    },
                },
                {
                    keyboard: true,
                    tooltip: {
                        use: tooltip,
                        className:
                            "font-sans shadow-none rounded-md bg-popover text-popover-foreground border p-2 text-xs",
                        anchor: "pointer",
                        placement: "auto",
                        content: (points) => shadcnTooltipContent(points),
                    },
                },
            ),
        [data],
    );

    return (
        <Card className="w-full max-w-xl">
            <CardHeader>
                <CardTitle>Comparative Polygon Spider Radar Evaluation</CardTitle>
                <CardDescription>
                    Multi-entity polygon radar overlay evaluating normalized multi-attribute metrics
                </CardDescription>
            </CardHeader>
            <CardContent>
                <div className="h-[270px] w-full">
                    <Chart
                        definition={definition}
                        renderer={motionRenderer}
                        height={270}
                        ariaLabel="Comparative Polygon Spider Radar Evaluation Chart"
                    />
                </div>
            </CardContent>
            <CardFooter className="flex-col items-start gap-2 text-sm">
                <div className="flex items-center gap-2 leading-none font-medium">
                    Product A vs Product B multi-axis attribute comparison{" "}
                    <ShieldAlert className="h-4 w-4 text-emerald-500" />
                </div>
                <div className="text-muted-foreground leading-none">
                    `radialGrid` with polygon shape and `angleGrid` guides construct comparative spider webs
                </div>
            </CardFooter>
        </Card>
    );
}

export default ComparativeRadar;
```
