# C chart tooltip presets 1

> Period comparison — revenue against last year with % change

A shadcn/ui block from the [@cnippet](https://ui.cnippet.dev/?utm_source=shadcn.exchange) registry, listed on [shadcn.exchange](https://shadcn.exchange/r/cnippet/c-chart-tooltip-presets-1).

- Page, with a live preview: https://shadcn.exchange/r/cnippet/c-chart-tooltip-presets-1
- Screenshot: https://shadcn.exchange/shot/cnippet/c-chart-tooltip-presets-1/light.png
- Registry item: https://ui.cnippet.dev/r/c-chart-tooltip-presets-1.json
- Categories: chart tooltip presets
- Listed: 2026-10-27, source last changed 2026-10-27

## Install

```bash
npx shadcn@latest add https://shadcn.exchange/r/cnippet/c-chart-tooltip-presets-1.json
```

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

## Dependencies

- Registry items: `@cnippet/chart-tooltip-presets`, `@cnippet/chart`, `@cnippet/chart-utils`

## Files

### `registry/default/chart-variants/c-chart-tooltip-presets-1.tsx`

```tsx
"use client";

import { CartesianGrid, Line, LineChart, XAxis } from "recharts";
import { ChartTooltipComparison } from "@/registry/default/charts/chart-tooltip-presets";
import { formatCurrency } from "@/registry/default/lib/chart-utils";
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
} from "@/registry/default/ui/chart";

const data = [
  { lastYear: 182000, month: "Jan", revenue: 214000 },
  { lastYear: 176000, month: "Feb", revenue: 208000 },
  { lastYear: 195000, month: "Mar", revenue: 236000 },
  { lastYear: 201000, month: "Apr", revenue: 229000 },
  { lastYear: 214000, month: "May", revenue: 251000 },
  { lastYear: 222000, month: "Jun", revenue: 248000 },
  { lastYear: 218000, month: "Jul", revenue: 266000 },
  { lastYear: 231000, month: "Aug", revenue: 274000 },
];

const config = {
  lastYear: { color: "var(--muted-foreground)", label: "Last year" },
  revenue: { color: "var(--chart-1)", label: "Revenue" },
} satisfies ChartConfig;

export default function RevenueVsLastYear() {
  return (
    <ChartContainer className="h-64 w-full" config={config}>
      <LineChart accessibilityLayer data={data}>
        <CartesianGrid vertical={false} />
        <XAxis
          axisLine={false}
          dataKey="month"
          tickLine={false}
          tickMargin={8}
        />
        <ChartTooltip
          content={
            <ChartTooltipComparison
              config={config}
              previous={{ revenue: "lastYear" }}
              valueFormatter={formatCurrency}
            />
          }
        />
        <Line
          dataKey="lastYear"
          dot={false}
          stroke="var(--color-lastYear)"
          strokeDasharray="4 4"
          strokeWidth={1.5}
          type="monotone"
        />
        <Line
          dataKey="revenue"
          dot={false}
          stroke="var(--color-revenue)"
          strokeWidth={2}
          type="monotone"
        />
      </LineChart>
    </ChartContainer>
  );
}
```
