# Seasonal Annual Polar Line Cycle

> Continuous 360-degree cyclical temperature polar chart.

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-polar-line).

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

## Install

```bash
npx shadcn@latest add https://shadcn.exchange/r/paceui/tanstack-charts-polar-line.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`
- Registry items: `card`

## Files

### `components/tanstack-charts/line/polar-line.tsx`

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

import { scaleLinear } from "d3-scale";
import { Compass } from "lucide-react";

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

interface PolarWeatherDatum {
    dayOfYear: number;
    angle: number;
    tempMax: number;
    date: Date;
}

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

const angleDomain = [0, 360];
const radiusDomain = [-10, 40];
const angleGridValues = [0, 45, 90, 135, 180, 225, 270, 315];
const radiusGridValues = [0, 10, 20, 30, 40];

function generateDemoData(): PolarWeatherDatum[] {
    const results: PolarWeatherDatum[] = [];
    const baseDate = new Date(Date.UTC(2024, 0, 1)).getTime();

    for (let day = 0; day < 365; day += 5) {
        const angle = (day / 365) * 360;
        const seasonal = 15 + 18 * Math.sin(((day - 80) / 365) * 2 * Math.PI);
        const noise = (Math.random() - 0.5) * 6;
        const tempMax = Number(Math.max(-5, seasonal + noise).toFixed(1));
        results.push({
            dayOfYear: day,
            angle,
            tempMax,
            date: new Date(baseDate + day * 24 * 60 * 60 * 1000),
        });
    }
    return results;
}

function shadcnTooltipContent<TDatum>(points: readonly ChartPoint<TDatum>[]) {
    if (points.length === 0) return { title: "", rows: [] };
    const d = points[0].datum as PolarWeatherDatum;
    if (!d) return { title: "", rows: [] };
    return {
        title: d.date.toLocaleDateString("en-US", { month: "short", day: "numeric", timeZone: "UTC" }),
        rows: [{ label: "Daily High Temp", value: `${d.tempMax}°C`, color: "var(--chart-1)" }],
    };
}

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

    const definition = useMemo(
        () =>
            defineChart(
                {
                    renderer: motionRenderer,
                    scales: {
                        x: null,
                        y: null,
                    },
                    marks: [
                        polar({
                            radiusRatio: 0.76,
                            scales: {
                                angle: { scale: scaleLinear().domain(angleDomain) },
                                radius: { scale: scaleLinear().domain(radiusDomain) },
                            },
                            guides: [
                                radialGrid({
                                    values: radiusGridValues,
                                    labels: false,
                                    stroke: "var(--border)",
                                    strokeOpacity: 0.5,
                                }),
                                angleGrid({
                                    values: angleGridValues,
                                    labels: false,
                                    stroke: "var(--border)",
                                    strokeOpacity: 0.5,
                                }),
                            ],
                            marks: [
                                radialLine(data, {
                                    id: "polar-line-series",
                                    angle: "angle",
                                    radius: "tempMax",
                                    stroke: "var(--chart-1)",
                                    strokeWidth: 2,
                                }),
                            ],
                        }),
                    ],
                    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>Seasonal Annual Polar Line Cycle</CardTitle>
                <CardDescription>
                    Continuous 360-degree cyclical temperature line mapping days of the year to angles
                </CardDescription>
            </CardHeader>
            <CardContent>
                <div className="h-[270px] w-full">
                    <Chart
                        definition={definition}
                        renderer={motionRenderer}
                        height={270}
                        ariaLabel="Seasonal Annual Polar Line Cycle Chart"
                    />
                </div>
            </CardContent>
            <CardFooter className="flex-col items-start gap-2 text-sm">
                <div className="flex items-center gap-2 leading-none font-medium">
                    Cyclical 365-day annual temperature curve in polar space{" "}
                    <Compass className="h-4 w-4 text-emerald-500" />
                </div>
                <div className="text-muted-foreground leading-none">
                    `radialLine` projects continuous temporal sequences around circular origin
                </div>
            </CardFooter>
        </Card>
    );
}

export default PolarLineChart;
```
