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 fits better. To show every observation, use a tick strip or a 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.
{
"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"
}
}import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 12 rows, as in the Spec tab; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "errorbar",
"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"
}
};
export function Example() {
return <Chart spec={spec} />;
}
<script setup lang="ts">
import { Chart } from "@opendata-ai/openchart-vue";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 12 rows, as in the Spec tab; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "errorbar",
"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"
}
};
</script>
<template>
<Chart :spec="spec" />
</template>
<script lang="ts">
import { Chart } from "@opendata-ai/openchart-svelte";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 12 rows, as in the Spec tab; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "errorbar",
"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"
}
};
</script>
<Chart {spec} />
import { createChart } from "@opendata-ai/openchart-vanilla";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 12 rows, as in the Spec tab; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "errorbar",
"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"
}
};
const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);
End caps
ticks: true adds a 6px cap at each end of the interval. The caps are decorative and their length is not configurable.
{
"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"
}
}import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 12 rows, as in the Spec tab; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": {
"type": "errorbar",
"ticks": true
},
"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"
}
};
export function Example() {
return <Chart spec={spec} />;
}
<script setup lang="ts">
import { Chart } from "@opendata-ai/openchart-vue";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 12 rows, as in the Spec tab; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": {
"type": "errorbar",
"ticks": true
},
"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"
}
};
</script>
<template>
<Chart :spec="spec" />
</template>
<script lang="ts">
import { Chart } from "@opendata-ai/openchart-svelte";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 12 rows, as in the Spec tab; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": {
"type": "errorbar",
"ticks": true
},
"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"
}
};
</script>
<Chart {spec} />
import { createChart } from "@opendata-ai/openchart-vanilla";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 12 rows, as in the Spec tab; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": {
"type": "errorbar",
"ticks": true
},
"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"
}
};
const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);
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.
{
"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"
}
}import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 12 rows, as in the Spec tab; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": {
"type": "errorbar",
"ticks": true
},
"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"
}
};
export function Example() {
return <Chart spec={spec} />;
}
<script setup lang="ts">
import { Chart } from "@opendata-ai/openchart-vue";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 12 rows, as in the Spec tab; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": {
"type": "errorbar",
"ticks": true
},
"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"
}
};
</script>
<template>
<Chart :spec="spec" />
</template>
<script lang="ts">
import { Chart } from "@opendata-ai/openchart-svelte";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 12 rows, as in the Spec tab; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": {
"type": "errorbar",
"ticks": true
},
"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"
}
};
</script>
<Chart {spec} />
import { createChart } from "@opendata-ai/openchart-vanilla";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 12 rows, as in the Spec tab; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": {
"type": "errorbar",
"ticks": true
},
"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"
}
};
const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);
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.
{
"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"
}
}import { Chart } from "@opendata-ai/openchart-react";
import type { LayerSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const spec: LayerSpec = {
"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"
}
};
export function Example() {
return <Chart spec={spec} />;
}
<script setup lang="ts">
import { Chart } from "@opendata-ai/openchart-vue";
import type { LayerSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const spec: LayerSpec = {
"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"
}
};
</script>
<template>
<Chart :spec="spec" />
</template>
<script lang="ts">
import { Chart } from "@opendata-ai/openchart-svelte";
import type { LayerSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const spec: LayerSpec = {
"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"
}
};
</script>
<Chart {spec} />
import { createChart } from "@opendata-ai/openchart-vanilla";
import type { LayerSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const spec: LayerSpec = {
"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"
}
};
const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);
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: every observation as a tick.
- Beeswarm: every observation as a dot.
- Density: the smoothed shape of the observations.
- Range: a start and an end per category.
- Trendlines: a fitted line over a scatter.
- Marks reference: the channels and options each mark type takes.