# Column

> Compare one value across ordered categories such as months or years with vertical columns, then annotate, color by sign and label them.

A column chart compares one number across a short, ordered set of categories, with each category on the x axis and the value as the height of its column. It suits time periods such as months or years.

Use a [bar chart](/docs/comparison/bar/) instead when the category names are long, since horizontal bars keep them at full length. Use a [line chart](/docs/change-over-time/line/) when the periods are many and the trend matters more than each value. The spec is the same as a bar chart; only the channels swap.

## A basic column chart

Set `mark` to `"bar"`, put the category on `x` and the number on `y`. Here `labels` prints every value above its column, formatted with a d3-format string.

```json
{
  "mark": "bar",
  "data": [
    {
      "month": "Jan",
      "jobs": 353
    },
    {
      "month": "Feb",
      "jobs": 275
    },
    {
      "month": "Mar",
      "jobs": 303
    },
    {
      "month": "Apr",
      "jobs": 175
    },
    {
      "month": "May",
      "jobs": 272
    },
    {
      "month": "Jun",
      "jobs": 206
    },
    {
      "month": "Jul",
      "jobs": 114
    },
    {
      "month": "Aug",
      "jobs": 142
    },
    {
      "month": "Sep",
      "jobs": 254
    },
    {
      "month": "Oct",
      "jobs": 12
    },
    {
      "month": "Nov",
      "jobs": 227
    },
    {
      "month": "Dec",
      "jobs": 256
    }
  ],
  "encoding": {
    "x": {
      "field": "month",
      "type": "nominal"
    },
    "y": {
      "field": "jobs",
      "type": "quantitative",
      "axis": {
        "title": "Jobs added (thousands)"
      }
    }
  },
  "labels": {
    "density": "all",
    "format": ",.0f"
  },
  "chrome": {
    "title": "US employers added jobs in every month of 2024",
    "subtitle": "Monthly US nonfarm payroll additions, 2024 (thousands of jobs)"
  }
}
```

## Annotating a column chart

A `refline` annotation draws a reference value in data units, here the yearly average on `y`. A `text` annotation attaches a note to one category by naming it on `x`, and `connector: true` connects the note to the column.

```json
{
  "mark": "bar",
  "data": [
    {
      "month": "Jan",
      "jobs": 353
    },
    {
      "month": "Feb",
      "jobs": 275
    },
    {
      "month": "Mar",
      "jobs": 303
    },
    {
      "month": "Apr",
      "jobs": 175
    },
    {
      "month": "May",
      "jobs": 272
    },
    {
      "month": "Jun",
      "jobs": 206
    },
    {
      "month": "Jul",
      "jobs": 114
    },
    {
      "month": "Aug",
      "jobs": 142
    },
    {
      "month": "Sep",
      "jobs": 254
    },
    {
      "month": "Oct",
      "jobs": 12
    },
    {
      "month": "Nov",
      "jobs": 227
    },
    {
      "month": "Dec",
      "jobs": 256
    }
  ],
  "encoding": {
    "x": {
      "field": "month",
      "type": "nominal"
    },
    "y": {
      "field": "jobs",
      "type": "quantitative",
      "axis": {
        "title": "Jobs added (thousands)"
      }
    }
  },
  "labels": {
    "density": "none"
  },
  "annotations": [
    {
      "type": "text",
      "x": "Oct",
      "y": 12,
      "text": "Hurricanes and strikes\nstalled October hiring",
      "anchor": "top",
      "offset": {
        "dy": -170
      },
      "connector": true
    },
    {
      "type": "refline",
      "y": 216,
      "label": "avg: 216K",
      "style": "dashed",
      "stroke": "#64748b",
      "strokeWidth": 1,
      "labelPlacement": "outside"
    }
  ],
  "chrome": {
    "title": "October's job gain was the smallest of 2024",
    "subtitle": "Monthly US nonfarm payroll additions, 2024 (thousands of jobs)"
  }
}
```

## Positive and negative values

Columns grow up from zero for positive values and down for negative ones. A color channel on a field in the data splits the two cases, and a `scale` with a `domain` and a `range` pairs each value with a color. A solid `refline` at `y: 0` marks the baseline.

These years are a decade apart until the last, five years after 2020, so `x` is `type: "temporal"` with `axis.format: "%Y"`: a time scale spaces the columns by date, where an ordinal axis would draw those five years as wide as a decade.

```json
{
  "mark": "bar",
  "data": [
    {
      "year": "1900",
      "anomaly": -0.08,
      "trend": "Cooler"
    },
    {
      "year": "1910",
      "anomaly": -0.43,
      "trend": "Cooler"
    },
    {
      "year": "1920",
      "anomaly": -0.27,
      "trend": "Cooler"
    },
    {
      "year": "1930",
      "anomaly": -0.16,
      "trend": "Cooler"
    },
    {
      "year": "1940",
      "anomaly": 0.12,
      "trend": "Warmer"
    },
    {
      "year": "1950",
      "anomaly": -0.17,
      "trend": "Cooler"
    },
    {
      "year": "1960",
      "anomaly": -0.03,
      "trend": "Cooler"
    },
    {
      "year": "1970",
      "anomaly": 0.03,
      "trend": "Warmer"
    },
    {
      "year": "1980",
      "anomaly": 0.26,
      "trend": "Warmer"
    },
    {
      "year": "1990",
      "anomaly": 0.45,
      "trend": "Warmer"
    },
    {
      "year": "2000",
      "anomaly": 0.39,
      "trend": "Warmer"
    },
    {
      "year": "2010",
      "anomaly": 0.72,
      "trend": "Warmer"
    },
    {
      "year": "2020",
      "anomaly": 1.01,
      "trend": "Warmer"
    },
    {
      "year": "2025",
      "anomaly": 1.19,
      "trend": "Warmer"
    }
  ],
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "format": "%Y"
      }
    },
    "y": {
      "field": "anomaly",
      "type": "quantitative",
      "axis": {
        "title": "Temperature anomaly (°C)",
        "format": "+.1f"
      }
    },
    "color": {
      "field": "trend",
      "type": "nominal",
      "scale": {
        "domain": [
          "Cooler",
          "Warmer"
        ],
        "range": [
          "#3b82c4",
          "#d1495b"
        ]
      }
    }
  },
  "labels": {
    "density": "none"
  },
  "annotations": [
    {
      "type": "refline",
      "y": 0,
      "style": "solid",
      "strokeWidth": 1
    }
  ],
  "chrome": {
    "title": "Every reading since 1970 is above the 1951–1980 average",
    "subtitle": "Global surface temperature, difference from the 1951–1980 average, 1900 to 2025 (°C)"
  }
}
```

## Long category names

When category names do not fit horizontally, the axis angles them, then truncates them, before it drops any ticks. If the names still crowd the axis, switch to a [bar chart](/docs/comparison/bar/).

```json
{
  "mark": "bar",
  "data": [
    {
      "department": "Research & Development",
      "budget": 42
    },
    {
      "department": "Marketing",
      "budget": 31
    },
    {
      "department": "Human Resources",
      "budget": 28
    },
    {
      "department": "IT Infrastructure",
      "budget": 24
    },
    {
      "department": "Customer Success",
      "budget": 19
    },
    {
      "department": "Legal & Compliance",
      "budget": 15
    },
    {
      "department": "Supply Chain",
      "budget": 12
    }
  ],
  "encoding": {
    "x": {
      "field": "department",
      "type": "nominal"
    },
    "y": {
      "field": "budget",
      "type": "quantitative",
      "axis": {
        "title": "Budget ($M)"
      }
    }
  },
  "chrome": {
    "title": "R&D has the largest budget",
    "subtitle": "Annual departmental budget allocations, FY 2025 ($M)"
  }
}
```

## Labels at the column ends

`labels.placement: "outside"` puts each value label at the end of its column, so labels follow the positive or negative end without changing the order of the data. `sort: null` keeps the order as authored, and `mark.size` sets an explicit column size.

```json
{
  "mark": {
    "type": "bar",
    "size": 28
  },
  "data": [
    {
      "name": "Research",
      "value": 128.4
    },
    {
      "name": "Operations",
      "value": 75.2
    },
    {
      "name": "Training",
      "value": 8.6
    },
    {
      "name": "Contingency",
      "value": 0
    },
    {
      "name": "Adjustments",
      "value": -24.3
    }
  ],
  "encoding": {
    "x": {
      "field": "name",
      "type": "nominal",
      "sort": null,
      "scale": {
        "paddingInner": 0.4
      }
    },
    "y": {
      "field": "value",
      "type": "quantitative",
      "axis": {
        "title": "Millions"
      }
    }
  },
  "labels": {
    "placement": "outside",
    "density": "all",
    "format": ".1f",
    "suffix": "M"
  },
  "legend": {
    "show": false
  },
  "chrome": {
    "title": "Positive and negative values follow their endpoints",
    "subtitle": "Budget allocations, millions"
  }
}
```

## Fields that matter

| Field | What it does |
| --- | --- |
| `mark: "bar"` | Draws bars. With the category on `x` and the number on `y` they run vertically. |
| `encoding.x` | The category channel. Use `type: "nominal"` for names, `"ordinal"` for evenly spaced ordered values such as months, and `"temporal"` for dates or years with uneven gaps. `sort: null` keeps the data order. |
| `encoding.y` | The value channel, with `axis.title` and `axis.format` for the axis. |
| `encoding.color` | Colors columns by a field. A `scale` with `domain` and `range` sets the colors. |
| `labels` | `density`, `format`, `placement` and `suffix` control the value labels. |
| `annotations` | A `refline` marks a value; a `text` note points at one category. |

## Related

- [Bar](/docs/comparison/bar/) for the horizontal form of the same chart.
- [Grouped and stacked bars](/docs/comparison/grouped-stacked/) for splitting each column into series.
- [Line](/docs/change-over-time/line/) for a trend across many periods.
- [Histogram](/docs/distribution/histogram/) for counting how often values fall in each range.
- [Marks reference](/docs/spec/marks/) lists the channels and options each mark type takes.
