# C heatmap 1

> Activity — sessions by weekday and hour

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-heatmap-1).

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

## Install

```bash
npx shadcn@latest add https://shadcn.exchange/r/cnippet/c-heatmap-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/heatmap`, `@cnippet/chart-card`

## Files

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

```tsx
"use client";

import { ChartCard } from "@/registry/default/charts/chart-card";
import { Heatmap } from "@/registry/default/charts/heatmap";

const days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
const hours = Array.from({ length: 24 }, (_, h) => String(h));

// Deterministic sessions: busy on weekday working hours, quiet at night and on weekends.
const data = days.flatMap((day, d) =>
  hours.map((hour, h) => {
    const work = h >= 9 && h <= 17 ? 1 : h >= 7 && h <= 21 ? 0.45 : 0.08;
    const weekend = d >= 5 ? 0.35 : 1;
    const wobble = ((d * 31 + h * 17) % 11) / 20;
    return {
      day,
      hour,
      sessions: Math.round(1200 * work * weekend * (0.8 + wobble)),
    };
  }),
);

export default function ActivityByHour() {
  return (
    <ChartCard
      className="max-w-2xl"
      description="Sessions by weekday and hour (UTC), last 4 weeks"
      title="When people use the app"
    >
      <Heatmap
        data={data}
        value="sessions"
        x="hour"
        xFormatter={(hour) => (Number(hour) % 3 === 0 ? hour : "")}
        y="day"
      />
    </ChartCard>
  );
}
```
