Box plot
A box plot summarizes a quantitative field inside each category. The box runs from the first quartile to the third. A line marks the median. Whiskers run to the last observation inside 1.5 times the interquartile range. Points beyond that fence are outlier dots.
When to use it
Use a box plot when you have several groups and the question is the middle, the spread, and the points that sit outside. Days to close compares five regions. South has a short deal and a long one past the whiskers. Weight by variety compares three orchards.
A strip draws every observation, which is the chart when the groups are few and the dots themselves are the story. A bar is one aggregate per category, a total or a mean you already computed. A histogram bins one sample and has no category axis.
Data
Each row is one observation. encoding.x is the category. encoding.y is the number. Days to close uses region and days. Weight by variety uses variety and grams.
The chart computes the quartiles. You do not pass q1, the median, or q3. Groups keep the order they first appear in the data. Each group takes the next series color. The renderer draws no legend.
a11y.alt is required. One sentence, 10 to 500 characters, with the comparison. The hover label on each box already lists the min, the quartiles, the median, and the max.
A spec that renders
This is the smallest box plot. version, type, and a11y.alt are required. Two groups, four observations each, and no mark. The box, the median line, and the whiskers are the chart.
{
"version": "1",
"type": "boxplot",
"data": [
{
"group": "A",
"days": 2
},
{
"group": "A",
"days": 4
},
{
"group": "A",
"days": 5
},
{
"group": "A",
"days": 9
},
{
"group": "B",
"days": 3
},
{
"group": "B",
"days": 3
},
{
"group": "B",
"days": 4
},
{
"group": "B",
"days": 6
}
],
"encoding": {
"x": "group",
"y": "days"
},
"a11y": {
"alt": "Group A stretches higher than group B."
}
}Install core and the adapter for your framework. The menu in the sidebar picks the snippet. spec is the JSON above.
npm install @chartkitdev/core
npm install @chartkitdev/react
import { Chart } from "@chartkitdev/react";
export function Panel() {
return <Chart spec={spec} />;
}npm install @chartkitdev/core
npm install @chartkitdev/vanilla
import { mount } from "@chartkitdev/vanilla";
const chart = mount(document.querySelector("#chart"), spec);
chart.update(spec);npm install @chartkitdev/core
npm install @chartkitdev/vue
<script setup>
import { Chart } from "@chartkitdev/vue";
</script>
<template>
<Chart :spec="spec" />
</template>npm install @chartkitdev/core
npm install @chartkitdev/svelte
<script>
import { Chart } from "@chartkitdev/svelte";
</script>
<Chart {spec} />npm install @chartkitdev/core
npm install @chartkitdev/astro
---
import { Chart } from "@chartkitdev/astro";
---
<Chart spec={spec} />npm install @chartkitdev/core
npm install @chartkitdev/solid
import { Chart } from "@chartkitdev/solid";
export function Panel() {
return <Chart spec={spec} />;
}npm install @chartkitdev/core
npm install @chartkitdev/qwik
import { component$ } from "@builder.io/qwik";
import { Chart } from "@chartkitdev/qwik";
export const Panel = component$(() => {
return <Chart spec={spec} />;
});npm install @chartkitdev/core
npm install @chartkitdev/angular
import { Component } from "@angular/core";
import { Chart } from "@chartkitdev/angular";
@Component({
standalone: true,
imports: [Chart],
template: `<ck-chart [spec]="spec" />`,
})
export class Panel {
spec = spec;
}npm install @chartkitdev/core
npm install @chartkitdev/element
import "@chartkitdev/element";
const chart = document.querySelector("chart-kit");
chart.spec = spec;The option below is a key on the spec. The demo changes that key and updates the chart and the snippet together.
Examples
The rail switches among existing box plot specs. Days to close is five regions of raw deals. South has points outside the whiskers. Weight by variety is fifteen crates in three boxes.
Tooltip
tooltip is on for a box plot when the key is omitted. Hovering a box shows the category, the whisker ends, the quartiles, and the median. An outlier dot names that point. tooltip: false turns the card off. tooltip: true turns it on.
{
"tooltip": false
}{
"tooltip": true
}tooltip.fields chooses the rows in the card. These examples omit the key. Turning the card off and on again puts that object back when the example had one, and deletes the key when the example omitted it.
What the chart always draws
The box, the median, the whiskers, and the outlier dots are the type. There is no mark.outliers switch, no mark.median switch, and no mark.orientation on a box plot. A horizontal reading of every point is a strip.
mark.gap changes the space between boxes, as a fraction of the band. The default gap is wide enough to separate the groups. Set a tighter gap in the playground. Theme presets live there too, with the full option list.