Charts

Listening Moods Radar Chart

Card with a radar chart scoring six listening moods out of 100, each axis label carrying its score so the values read without the shape. Client component on recharts 3.8.

Free, MIT licenseOpen in Browse
"use client"

import { PolarAngleAxis, PolarGrid, Radar, RadarChart } from "recharts"

import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import {
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  type ChartConfig,
} from "@/components/ui/chart"

// The copy: change text here, not in the markup.
const COPY = {
  title: "Listening profile",
  description: "How October's listening splits by mood, out of 100",
} as const

const MOODS = [
  { mood: "Calm", score: 82 },
  { mood: "Focus", score: 74 },
  { mood: "Warm", score: 63 },
  { mood: "Bright", score: 38 },
  { mood: "Energy", score: 46 },
  { mood: "Dark", score: 55 },
]

const CHART_CONFIG = {
  score: { label: "Score", color: "var(--chart-2)" },
} satisfies ChartConfig

// Each axis prints its score, so the shape is never the only record of it.
const SCORES = new Map(MOODS.map((entry) => [entry.mood, entry.score]))

export default function RadarChart01() {
  return (
    <Card className="mx-auto w-full max-w-md">
      <CardHeader>
        <CardTitle>
          <h2>{COPY.title}</h2>
        </CardTitle>
        <CardDescription>{COPY.description}</CardDescription>
      </CardHeader>
      <CardContent>
        <ChartContainer
          config={CHART_CONFIG}
          className="mx-auto aspect-square max-h-72"
        >
          <RadarChart
            accessibilityLayer
            data={MOODS}
            outerRadius="62%"
            margin={{ left: 24, right: 24 }}
          >
            <ChartTooltip
              cursor={false}
              content={<ChartTooltipContent hideLabel />}
            />
            <PolarGrid />
            {/* Stock ChartContainer's label color misses recharts 3's label layer. */}
            <PolarAngleAxis
              tick={{ fill: "var(--muted-foreground)" }}
              dataKey="mood"
              tickFormatter={(mood: string) => `${mood} ${SCORES.get(mood)}`}
            />
            <Radar
              dataKey="score"
              fill="var(--color-score)"
              fillOpacity={0.2}
              stroke="var(--color-score)"
              strokeWidth={2}
              dot={{ r: 3, fillOpacity: 1 }}
            />
          </RadarChart>
        </ChartContainer>
      </CardContent>
    </Card>
  )
}

Installation

pnpm dlx shadcn add @01orbital/radar-chart-01
npx shadcn add @01orbital/radar-chart-01
yarn shadcn add @01orbital/radar-chart-01
bunx --bun shadcn add @01orbital/radar-chart-01

Free under the MIT license. Add the @01orbital registry to components.json once (install guide), then run the command.

It lands at components/blocks/charts/radar-chart-01/index.tsx, as source you own and edit.

Usage

import RadarChart01 from "@/components/blocks/charts/radar-chart-01"

export default function Example() {
  return <RadarChart01 />
}

Dependencies

npm: recharts@3.8.0. The CLI installs them for you.

Registry pieces it installs with it:

  • card
  • chart