# Calendar

> Lay a daily value out as a grid of weeks and weekdays, one colored cell per day, to read seasonality and streaks across a year or several.

A calendar heatmap draws one cell per day, with weeks as columns and weekdays as rows, and colors each cell by that day's value. It suits daily data where seasonality, streaks and weekday patterns matter more than exact values.

Use a [line chart](/docs/change-over-time/line/) when the reader needs to read values off an axis or compare a few series, and a [heatmap](/docs/correlation/heatmap/) when the two axes are categories rather than dates. A calendar has no axes at all, so the color legend is the only way to read a number.

## A basic calendar

`x` is the daily date with `type: "temporal"`, one row per day, and `color` is the quantitative value. There is no `y` channel, because the calendar computes its own weeks-by-weekdays layout. Days with no data row render as empty cells, so the grid always shows the whole year, and these demos fill a few weeks of it.

A diverging scheme such as `redBlue` suits values that run above and below a normal, and `reverse: true` makes warm days red. The scale spans the data's minimum to maximum, so set a symmetric `domain` to put the neutral color at zero. `format` sets how the legend prints values.

```json
{
  "mark": "calendar",
  "data": [
    {
      "date": "2024-06-03",
      "anomaly": 0.1
    },
    {
      "date": "2024-06-04",
      "anomaly": -0.9
    },
    {
      "date": "2024-06-05",
      "anomaly": 1.2
    },
    {
      "date": "2024-06-06",
      "anomaly": -0.9
    },
    {
      "date": "2024-06-07",
      "anomaly": 0.7
    },
    {
      "date": "2024-06-08",
      "anomaly": 0.7
    },
    {
      "date": "2024-06-09",
      "anomaly": 0.9
    },
    {
      "date": "2024-06-10",
      "anomaly": -0.1
    },
    {
      "date": "2024-06-11",
      "anomaly": -0.8
    },
    {
      "date": "2024-06-12",
      "anomaly": 0.3
    },
    {
      "date": "2024-06-13",
      "anomaly": 0.7
    },
    {
      "date": "2024-06-14",
      "anomaly": 1.2
    },
    {
      "date": "2024-06-15",
      "anomaly": 0
    },
    {
      "date": "2024-06-16",
      "anomaly": -0.7
    },
    {
      "date": "2024-06-17",
      "anomaly": 0.9
    },
    {
      "date": "2024-06-18",
      "anomaly": 1.2
    },
    {
      "date": "2024-06-19",
      "anomaly": -0.4
    },
    {
      "date": "2024-06-20",
      "anomaly": -0.6
    },
    {
      "date": "2024-06-21",
      "anomaly": 0
    },
    {
      "date": "2024-06-22",
      "anomaly": 0.7
    },
    {
      "date": "2024-06-23",
      "anomaly": 1.4
    },
    {
      "date": "2024-06-24",
      "anomaly": 0
    },
    {
      "date": "2024-06-25",
      "anomaly": 0.2
    },
    {
      "date": "2024-06-26",
      "anomaly": -0.4
    },
    {
      "date": "2024-06-27",
      "anomaly": 0.4
    },
    {
      "date": "2024-06-28",
      "anomaly": 0.4
    },
    {
      "date": "2024-06-29",
      "anomaly": 1.5
    },
    {
      "date": "2024-06-30",
      "anomaly": 1
    },
    {
      "date": "2024-07-01",
      "anomaly": 0.3
    },
    {
      "date": "2024-07-02",
      "anomaly": 0.4
    },
    {
      "date": "2024-07-03",
      "anomaly": 0.9
    },
    {
      "date": "2024-07-04",
      "anomaly": 0.6
    },
    {
      "date": "2024-07-05",
      "anomaly": 1.5
    },
    {
      "date": "2024-07-06",
      "anomaly": -0.6
    },
    {
      "date": "2024-07-07",
      "anomaly": -0.3
    }
  ],
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal"
    },
    "color": {
      "field": "anomaly",
      "type": "quantitative",
      "scale": {
        "scheme": "redBlue",
        "reverse": true,
        "domain": [
          -2.5,
          2.5
        ]
      },
      "format": "+.1f"
    }
  },
  "chrome": {
    "title": "Five summer weeks of daily temperature anomalies",
    "subtitle": "Daily temperature anomaly against the seasonal normal, degrees C. One cell per day, weeks run left to right."
  }
}
```

## Sunday weeks and rounder cells

Two mark options change the grid. `weekStart` sets which weekday sits in the top row, `"monday"` by default or `"sunday"`. `cellRadius` sets the corner radius of each day cell in pixels. Default 2. This demo also swaps in a sequential scheme, `"blues"`, because the values here run from low to high rather than around a midpoint.

```json
{
  "mark": {
    "type": "calendar",
    "weekStart": "sunday",
    "cellRadius": 6
  },
  "data": [
    {
      "date": "2024-06-02",
      "reading": 3.2
    },
    {
      "date": "2024-06-03",
      "reading": 1.6
    },
    {
      "date": "2024-06-04",
      "reading": 1.8
    },
    {
      "date": "2024-06-05",
      "reading": 1.3
    },
    {
      "date": "2024-06-06",
      "reading": 1.8
    },
    {
      "date": "2024-06-07",
      "reading": 1.2
    },
    {
      "date": "2024-06-08",
      "reading": 3.2
    },
    {
      "date": "2024-06-09",
      "reading": 2.9
    },
    {
      "date": "2024-06-10",
      "reading": 2.5
    },
    {
      "date": "2024-06-11",
      "reading": 2.1
    },
    {
      "date": "2024-06-12",
      "reading": 3.1
    },
    {
      "date": "2024-06-13",
      "reading": 3.3
    },
    {
      "date": "2024-06-14",
      "reading": 3.3
    },
    {
      "date": "2024-06-15",
      "reading": 1.7
    },
    {
      "date": "2024-06-16",
      "reading": 1.9
    },
    {
      "date": "2024-06-17",
      "reading": 2.4
    },
    {
      "date": "2024-06-18",
      "reading": 2.4
    },
    {
      "date": "2024-06-19",
      "reading": 2.1
    },
    {
      "date": "2024-06-20",
      "reading": 3.4
    },
    {
      "date": "2024-06-21",
      "reading": 2.3
    },
    {
      "date": "2024-06-22",
      "reading": 2.5
    },
    {
      "date": "2024-06-23",
      "reading": 2.7
    },
    {
      "date": "2024-06-24",
      "reading": 3
    },
    {
      "date": "2024-06-25",
      "reading": 2.6
    },
    {
      "date": "2024-06-26",
      "reading": 3.2
    },
    {
      "date": "2024-06-27",
      "reading": 2.2
    },
    {
      "date": "2024-06-28",
      "reading": 3.6
    },
    {
      "date": "2024-06-29",
      "reading": 1.6
    }
  ],
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal"
    },
    "color": {
      "field": "reading",
      "type": "quantitative",
      "scale": {
        "scheme": "blues"
      },
      "format": ".1f"
    }
  },
  "chrome": {
    "title": "Weeks start on Sunday and cells have rounder corners",
    "subtitle": "Daily reading, one cell per day. weekStart: sunday, cellRadius: 6."
  }
}
```

## Several years

Data that spans several years splits into one band per year, each a full calendar year, stacked one above the other with the year as a label. The bands share a single color scale and a single legend, so colors compare across years. This demo puts the same four June weeks of 2023 and 2024 in two bands.

```json
{
  "mark": "calendar",
  "data": [
    {
      "date": "2023-06-05",
      "anomaly": -0.1
    },
    {
      "date": "2023-06-06",
      "anomaly": 0
    },
    {
      "date": "2023-06-07",
      "anomaly": 1
    },
    {
      "date": "2023-06-08",
      "anomaly": 1
    },
    {
      "date": "2023-06-09",
      "anomaly": 0.9
    },
    {
      "date": "2023-06-10",
      "anomaly": 1.1
    },
    {
      "date": "2023-06-11",
      "anomaly": -0.3
    },
    {
      "date": "2023-06-12",
      "anomaly": 1.1
    },
    {
      "date": "2023-06-13",
      "anomaly": -0.8
    },
    {
      "date": "2023-06-14",
      "anomaly": 0.4
    },
    {
      "date": "2023-06-15",
      "anomaly": 1.5
    },
    {
      "date": "2023-06-16",
      "anomaly": 1.4
    },
    {
      "date": "2023-06-17",
      "anomaly": 0.2
    },
    {
      "date": "2023-06-18",
      "anomaly": 0.7
    },
    {
      "date": "2023-06-19",
      "anomaly": 0.1
    },
    {
      "date": "2023-06-20",
      "anomaly": 0.1
    },
    {
      "date": "2023-06-21",
      "anomaly": 1.5
    },
    {
      "date": "2023-06-22",
      "anomaly": -0.1
    },
    {
      "date": "2023-06-23",
      "anomaly": -0.7
    },
    {
      "date": "2023-06-24",
      "anomaly": 0.1
    },
    {
      "date": "2023-06-25",
      "anomaly": 1.2
    },
    {
      "date": "2023-06-26",
      "anomaly": 0.8
    },
    {
      "date": "2023-06-27",
      "anomaly": -0.5
    },
    {
      "date": "2023-06-28",
      "anomaly": 1
    },
    {
      "date": "2023-06-29",
      "anomaly": 1.2
    },
    {
      "date": "2023-06-30",
      "anomaly": 1.2
    },
    {
      "date": "2023-07-01",
      "anomaly": -0.2
    },
    {
      "date": "2023-07-02",
      "anomaly": 0.3
    },
    {
      "date": "2024-06-03",
      "anomaly": 0.1
    },
    {
      "date": "2024-06-04",
      "anomaly": -0.9
    },
    {
      "date": "2024-06-05",
      "anomaly": 1.2
    },
    {
      "date": "2024-06-06",
      "anomaly": -0.9
    },
    {
      "date": "2024-06-07",
      "anomaly": 0.7
    },
    {
      "date": "2024-06-08",
      "anomaly": 0.7
    },
    {
      "date": "2024-06-09",
      "anomaly": 0.9
    },
    {
      "date": "2024-06-10",
      "anomaly": -0.1
    },
    {
      "date": "2024-06-11",
      "anomaly": -0.8
    },
    {
      "date": "2024-06-12",
      "anomaly": 0.3
    },
    {
      "date": "2024-06-13",
      "anomaly": 0.7
    },
    {
      "date": "2024-06-14",
      "anomaly": 1.2
    },
    {
      "date": "2024-06-15",
      "anomaly": 0
    },
    {
      "date": "2024-06-16",
      "anomaly": -0.7
    },
    {
      "date": "2024-06-17",
      "anomaly": 0.9
    },
    {
      "date": "2024-06-18",
      "anomaly": 1.2
    },
    {
      "date": "2024-06-19",
      "anomaly": -0.4
    },
    {
      "date": "2024-06-20",
      "anomaly": -0.6
    },
    {
      "date": "2024-06-21",
      "anomaly": 0
    },
    {
      "date": "2024-06-22",
      "anomaly": 0.7
    },
    {
      "date": "2024-06-23",
      "anomaly": 1.4
    },
    {
      "date": "2024-06-24",
      "anomaly": 0
    },
    {
      "date": "2024-06-25",
      "anomaly": 0.2
    },
    {
      "date": "2024-06-26",
      "anomaly": -0.4
    },
    {
      "date": "2024-06-27",
      "anomaly": 0.4
    },
    {
      "date": "2024-06-28",
      "anomaly": 0.4
    },
    {
      "date": "2024-06-29",
      "anomaly": 1.5
    },
    {
      "date": "2024-06-30",
      "anomaly": 1
    }
  ],
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal"
    },
    "color": {
      "field": "anomaly",
      "type": "quantitative",
      "scale": {
        "scheme": "redBlue",
        "reverse": true,
        "domain": [
          -2.5,
          2.5
        ]
      },
      "format": "+.1f"
    }
  },
  "chrome": {
    "title": "June 2023 and June 2024, one band per year",
    "subtitle": "Daily temperature anomaly against the seasonal normal, degrees C. Both bands share one color scale."
  }
}
```

## Fields that matter

| Field | What it does |
| --- | --- |
| `mark` | `"calendar"`, or an object with `weekStart` and `cellRadius`. |
| `encoding.x` | The date of each day, `type: "temporal"`. |
| `encoding.color` | The quantitative value that colors each cell. It also drives the legend. |
| `encoding.color.scale.scheme` | A named color scheme, such as `"redBlue"` or `"blues"`. |
| `encoding.color.scale.reverse` | Flips the direction of the scheme. |
| `encoding.color.format` | A d3-format string for the legend values. |
| `mark.weekStart` | `"monday"` or `"sunday"`: the weekday in the top row. |
| `mark.cellRadius` | Corner radius of day cells, in pixels. Default 2. |

## Related

- [Line](/docs/change-over-time/line/) for daily values read against an axis.
- [Sparkline](/docs/change-over-time/sparkline/) for a small trend without a calendar layout.
- [Heatmap](/docs/correlation/heatmap/) for color over two categorical axes.
- [Histogram](/docs/distribution/histogram/) for how often each value occurs.
- [Marks reference](/docs/spec/marks/) lists the channels and options each mark type takes.
