# Area Chart Default

> A default single area chart displaying website visitor trends built with TanStack Charts.

A shadcn/ui block from the [@pacekit](https://ui.pacekit.dev/?utm_source=shadcn.exchange) registry, listed on [shadcn.exchange](https://shadcn.exchange/r/pacekit/tanstack-charts-area-default).

- Page, with a live preview: https://shadcn.exchange/r/pacekit/tanstack-charts-area-default
- Screenshot: https://abzjhwgwpdpz7ua5.public.blob.vercel-storage.com/shots/pacekit/tanstack-charts-area-default-light-449a05889724ba72.png
- Registry item: https://ui.pacekit.dev/r/tanstack-charts-area-default.json
- Listed: 2026-10-21, source last changed 2026-10-21

## Install

```bash
npx shadcn@latest add https://shadcn.exchange/r/pacekit/tanstack-charts-area-default.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/area/area-chart-default.tsx`

```tsx
import { type ChartPoint, areaY, d3Curve, defineChart } from "@tanstack/charts";
import { motion } from "@tanstack/charts/motion";
import { tooltip } from "@tanstack/charts/tooltip";
import { Chart } from "@tanstack/react-charts/core";
import { useMemo } from "react";

import { scaleLinear, scalePoint } from "d3-scale";
import { curveNatural } from "d3-shape";
import { TrendingUp } from "lucide-react";

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

interface MonthDatum {
    month: string;
    desktop: number;
}

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

function generateDemoData(): MonthDatum[] {
    return [
        { month: "January", desktop: 186 },
        { month: "February", desktop: 305 },
        { month: "March", desktop: 237 },
        { month: "April", desktop: 73 },
        { month: "May", desktop: 209 },
        { month: "June", desktop: 214 },
    ];
}

function shadcnTooltipContent<TDatum>(points: readonly ChartPoint<TDatum>[]) {
    return {
        title: String(points[0]?.xValue ?? ""),
        rows: points.map((point) => ({
            label: "Desktop",
            value: Number(point.yValue ?? point.xValue ?? 0).toLocaleString("en-US"),
            color: point.color,
        })),
    };
}

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

    const definition = useMemo(
        () =>
            defineChart(
                {
                    renderer: motionRenderer,
                    motion: {
                        transition: { type: "spring", stiffness: 170, damping: 18, mass: 1 },
                    },
                    marks: [
                        areaY(data, {
                            id: "visitor-area",
                            x: "month",
                            y: "desktop",
                            curve: d3Curve(curveNatural),
                            fill: "var(--chart-1)",
                            fillOpacity: 0.4,
                            stroke: "var(--chart-1)",
                            strokeWidth: 1.5,
                        }),
                    ],
                    scales: {
                        x: {
                            scale: scalePoint,
                            axis: {
                                line: false,
                                ticks: {
                                    size: 0,
                                    padding: 10,
                                    format: (value: string) => value.slice(0, 3),
                                },
                            },
                        },
                        y: {
                            scale: scaleLinear,
                            grid: true,
                            axis: { line: false, ticks: false, tickLabels: false },
                        },
                    },
                    color: {
                        domain: ["desktop"],
                        range: ["var(--chart-1)"],
                    },
                    margin: { top: 10, right: 12, bottom: 30, left: 12 },
                    theme: {
                        foreground: "var(--muted-foreground)",
                        grid: "var(--border)",
                        background: "transparent",
                    },
                },
                {
                    focus: "group-x",
                    tooltip: {
                        use: tooltip,
                        motion: { type: "spring", stiffness: 170, damping: 18 },
                        className:
                            "font-sans shadow-none rounded-md bg-popover text-popover-foreground border p-2 text-xs",
                        anchor: "group-center",
                        placement: "auto",
                        sort: "color-domain",
                        content: (points) => shadcnTooltipContent(points),
                    },
                },
            ),
        [data],
    );

    return (
        <Card className="w-full max-w-2xl">
            <CardHeader>
                <CardTitle>Monthly Active Visitors</CardTitle>
                <CardDescription>Unique web visitors across web and app sessions</CardDescription>
            </CardHeader>
            <CardContent>
                <div className="h-[250px] w-full">
                    <Chart
                        definition={definition}
                        renderer={motionRenderer}
                        height={250}
                        ariaLabel="Monthly Active Visitors Chart"
                    />
                </div>
            </CardContent>
            <CardFooter className="flex-col items-start gap-2 text-sm">
                <div className="flex items-center gap-2 leading-none font-medium">
                    Organic conversion up by 5.2% this month <TrendingUp className="h-4 w-4 text-emerald-500" />
                </div>
                <div className="text-muted-foreground leading-none">January - June 2024</div>
            </CardFooter>
        </Card>
    );
}

export default AreaChartDefault;
```
