# Error bars

> Draw an interval between two supplied bounds, vertical or horizontal, with optional end caps, and layer a point to mark an estimate inside it.

An error bar draws an interval from a lower bound to an upper bound for each row, so a reader sees how far a value could range. OpenChart never computes confidence intervals, standard errors or quartiles. You aggregate upstream and supply the two bounds as fields.

Because the bounds are just fields, the mark also draws any low-to-high span, such as a monthly temperature range. To compare a start and an end value per category, a [range chart](/docs/comparison/range/) fits better. To show every observation, use a [tick strip](/docs/distribution/tick-strip/) or a [beeswarm](/docs/distribution/beeswarm/).

## A basic interval

Set `mark` to `"errorbar"`, put the category on `x`, the lower bound on `y` and the upper bound on `y2`. Supply exactly one second endpoint, either `y2` or `x2`. A row with a missing bound draws no interval.

```json
{
  "mark": "errorbar",
  "data": [
    {
      "month": "Jan",
      "low": 3.5,
      "high": 9.3
    },
    {
      "month": "Feb",
      "low": 0.9,
      "high": 9.2
    },
    {
      "month": "Mar",
      "low": 3.2,
      "high": 10.8
    },
    {
      "month": "Apr",
      "low": 9.4,
      "high": 19
    },
    {
      "month": "May",
      "low": 12,
      "high": 22.1
    },
    {
      "month": "Jun",
      "low": 16.8,
      "high": 25.4
    },
    {
      "month": "Jul",
      "low": 22.1,
      "high": 30.2
    },
    {
      "month": "Aug",
      "low": 20.2,
      "high": 27.6
    },
    {
      "month": "Sep",
      "low": 17.3,
      "high": 24.3
    },
    {
      "month": "Oct",
      "low": 12.4,
      "high": 19.3
    },
    {
      "month": "Nov",
      "low": 4.5,
      "high": 11.8
    },
    {
      "month": "Dec",
      "low": 4.2,
      "high": 9.8
    }
  ],
  "encoding": {
    "x": {
      "field": "month",
      "type": "nominal"
    },
    "y": {
      "field": "low",
      "type": "quantitative",
      "axis": {
        "title": "Temperature (°C)"
      }
    },
    "y2": {
      "field": "high",
      "type": "quantitative"
    }
  },
  "chrome": {
    "title": "New York's monthly averages run from about 1°C to 30°C",
    "subtitle": "Average daily low to high temperature by month, Central Park, 2023"
  }
}
```

## End caps

`ticks: true` adds a 6px cap at each end of the interval. The caps are decorative and their length is not configurable.

```json
{
  "mark": {
    "type": "errorbar",
    "ticks": true
  },
  "data": [
    {
      "month": "Jan",
      "low": 3.5,
      "high": 9.3
    },
    {
      "month": "Feb",
      "low": 0.9,
      "high": 9.2
    },
    {
      "month": "Mar",
      "low": 3.2,
      "high": 10.8
    },
    {
      "month": "Apr",
      "low": 9.4,
      "high": 19
    },
    {
      "month": "May",
      "low": 12,
      "high": 22.1
    },
    {
      "month": "Jun",
      "low": 16.8,
      "high": 25.4
    },
    {
      "month": "Jul",
      "low": 22.1,
      "high": 30.2
    },
    {
      "month": "Aug",
      "low": 20.2,
      "high": 27.6
    },
    {
      "month": "Sep",
      "low": 17.3,
      "high": 24.3
    },
    {
      "month": "Oct",
      "low": 12.4,
      "high": 19.3
    },
    {
      "month": "Nov",
      "low": 4.5,
      "high": 11.8
    },
    {
      "month": "Dec",
      "low": 4.2,
      "high": 9.8
    }
  ],
  "encoding": {
    "x": {
      "field": "month",
      "type": "nominal"
    },
    "y": {
      "field": "low",
      "type": "quantitative",
      "axis": {
        "title": "Temperature (°C)"
      }
    },
    "y2": {
      "field": "high",
      "type": "quantitative"
    }
  },
  "chrome": {
    "title": "End caps mark where each interval stops",
    "subtitle": "Average daily low to high temperature by month, Central Park, 2023"
  }
}
```

## Horizontal intervals

Put the category on `y` and the bounds on `x` and `x2` for a horizontal interval. The default stroke is 2px at 0.35 opacity in the series color, and `mark.stroke` overrides the color.

```json
{
  "mark": {
    "type": "errorbar",
    "ticks": true
  },
  "data": [
    {
      "month": "Jan",
      "low": 3.5,
      "high": 9.3
    },
    {
      "month": "Feb",
      "low": 0.9,
      "high": 9.2
    },
    {
      "month": "Mar",
      "low": 3.2,
      "high": 10.8
    },
    {
      "month": "Apr",
      "low": 9.4,
      "high": 19
    },
    {
      "month": "May",
      "low": 12,
      "high": 22.1
    },
    {
      "month": "Jun",
      "low": 16.8,
      "high": 25.4
    },
    {
      "month": "Jul",
      "low": 22.1,
      "high": 30.2
    },
    {
      "month": "Aug",
      "low": 20.2,
      "high": 27.6
    },
    {
      "month": "Sep",
      "low": 17.3,
      "high": 24.3
    },
    {
      "month": "Oct",
      "low": 12.4,
      "high": 19.3
    },
    {
      "month": "Nov",
      "low": 4.5,
      "high": 11.8
    },
    {
      "month": "Dec",
      "low": 4.2,
      "high": 9.8
    }
  ],
  "encoding": {
    "y": {
      "field": "month",
      "type": "nominal"
    },
    "x": {
      "field": "low",
      "type": "quantitative",
      "axis": {
        "title": "Temperature (°C)"
      }
    },
    "x2": {
      "field": "high",
      "type": "quantitative"
    }
  },
  "chrome": {
    "title": "The same intervals on a horizontal axis",
    "subtitle": "Average daily low to high temperature by month, Central Park, 2023"
  }
}
```

## An estimate inside its interval

To show the estimate itself, use a layer spec with two children on the same data: an `errorbar` mark and a `point` mark. The point mark draws a fitted trend line by default, so set `trendline: false` on that layer.

```json
{
  "layer": [
    {
      "mark": {
        "type": "errorbar",
        "ticks": true
      },
      "data": [
        {
          "agent": "Claude",
          "lower": 0.62,
          "upper": 0.9,
          "value": 0.8
        },
        {
          "agent": "Codex",
          "lower": 0.7,
          "upper": 0.96,
          "value": 0.88
        }
      ],
      "encoding": {
        "x": {
          "field": "lower",
          "type": "quantitative",
          "scale": {
            "domain": [
              0,
              1
            ]
          },
          "axis": {
            "title": "Pass rate",
            "format": ".0%"
          }
        },
        "x2": {
          "field": "upper",
          "type": "quantitative"
        },
        "y": {
          "field": "agent",
          "type": "nominal"
        }
      }
    },
    {
      "mark": {
        "type": "point",
        "trendline": false
      },
      "data": [
        {
          "agent": "Claude",
          "lower": 0.62,
          "upper": 0.9,
          "value": 0.8
        },
        {
          "agent": "Codex",
          "lower": 0.7,
          "upper": 0.96,
          "value": 0.88
        }
      ],
      "encoding": {
        "x": {
          "field": "value",
          "type": "quantitative"
        },
        "y": {
          "field": "agent",
          "type": "nominal"
        }
      }
    }
  ],
  "chrome": {
    "title": "A layered point shows the estimate inside its interval",
    "subtitle": "Pass rate with a supplied interval"
  }
}
```

## Fields that matter

| Field | What it does |
| --- | --- |
| `mark` | `"errorbar"`, or `{ type: "errorbar", ticks: true }` for end caps. |
| `mark.ticks` | Draws 6px end caps. Defaults to false. |
| `mark.stroke`, `mark.strokeWidth`, `mark.opacity` | Override the series color, the 2px width and the 0.35 opacity. |
| `encoding.y`, `encoding.y2` | The lower and upper bounds for a vertical interval. The category goes on `x`. |
| `encoding.x`, `encoding.x2` | The lower and upper bounds for a horizontal interval. The category goes on `y`. |
| `layer` | Combines an `errorbar` child with a `point` child to mark the estimate. |

## Related

- [Tick strip](/docs/distribution/tick-strip/): every observation as a tick.
- [Beeswarm](/docs/distribution/beeswarm/): every observation as a dot.
- [Density](/docs/distribution/density/): the smoothed shape of the observations.
- [Range](/docs/comparison/range/): a start and an end per category.
- [Trendlines](/docs/correlation/trendlines/): a fitted line over a scatter.
- [Marks reference](/docs/spec/marks/): the channels and options each mark type takes.
