Lollipop chart vs bar chart
Lollipop charts suit long ranked lists better than bars do, but the stems still have to start at zero.
OpenChart3 min read
Made with OpenChart. How to build this scatter plot
Argentina’s diet comes to about 2,172 kg of CO2 per person a year, the most of the 130 countries in a food-emissions dataset, and beef accounts for 79% of it. Ranking the 20 highest countries means drawing 20 long values that sit close together, which is where a lollipop chart beats bars.
A lollipop thins each bar to a stem and puts a dot at the end. It encodes the same thing as a bar, a value as a distance from zero, with less ink.
Long ranked lists
As bars, the 20 values run from 1,420 to 2,172 kg and fill most of the plot. The chart becomes a dark block, and the eye has to find each bar’s end inside it.
Made with OpenChart. How to build this bar chart
{
"mark": "bar",
"data": [
{
"country": "Argentina",
"kgCo2": 2172.4
},
{
"country": "Australia",
"kgCo2": 1938.7
},
{
"country": "Albania",
"kgCo2": 1777.9
},
{
"country": "New Zealand",
"kgCo2": 1751
},
{
"country": "Iceland",
"kgCo2": 1731.4
},
{
"country": "United States",
"kgCo2": 1718.9
},
// … 14 more rows; Copy includes them
],
"encoding": {
"x": {
"field": "kgCo2",
"type": "quantitative",
"axis": {
"title": "kg CO2 per person per year",
"format": ",.0f"
}
},
"y": {
"field": "country",
"type": "nominal",
"sort": "-x"
}
},
"labels": {
"density": "none"
},
"theme": {
"colors": {
"categorical": [
{
"light": "#0e7490",
"dark": "#22a3c4"
}
]
}
},
"chrome": {
"title": "Argentina's diet produces 2,172 kg of CO2 per person a year, the most of 130 countries",
"subtitle": "Kilograms of CO2 per person per year from 11 food types, the 20 highest of 130 countries (no year stated)"
}
}import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 20 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "bar",
"encoding": {
"x": {
"field": "kgCo2",
"type": "quantitative",
"axis": {
"title": "kg CO2 per person per year",
"format": ",.0f"
}
},
"y": {
"field": "country",
"type": "nominal",
"sort": "-x"
}
},
"labels": {
"density": "none"
},
"theme": {
"colors": {
"categorical": [
{
"light": "#0e7490",
"dark": "#22a3c4"
}
]
}
},
"chrome": {
"title": "Argentina's diet produces 2,172 kg of CO2 per person a year, the most of 130 countries",
"subtitle": "Kilograms of CO2 per person per year from 11 food types, the 20 highest of 130 countries (no year stated)"
}
};
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 = [/* 20 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "bar",
"encoding": {
"x": {
"field": "kgCo2",
"type": "quantitative",
"axis": {
"title": "kg CO2 per person per year",
"format": ",.0f"
}
},
"y": {
"field": "country",
"type": "nominal",
"sort": "-x"
}
},
"labels": {
"density": "none"
},
"theme": {
"colors": {
"categorical": [
{
"light": "#0e7490",
"dark": "#22a3c4"
}
]
}
},
"chrome": {
"title": "Argentina's diet produces 2,172 kg of CO2 per person a year, the most of 130 countries",
"subtitle": "Kilograms of CO2 per person per year from 11 food types, the 20 highest of 130 countries (no year stated)"
}
};
</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 = [/* 20 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "bar",
"encoding": {
"x": {
"field": "kgCo2",
"type": "quantitative",
"axis": {
"title": "kg CO2 per person per year",
"format": ",.0f"
}
},
"y": {
"field": "country",
"type": "nominal",
"sort": "-x"
}
},
"labels": {
"density": "none"
},
"theme": {
"colors": {
"categorical": [
{
"light": "#0e7490",
"dark": "#22a3c4"
}
]
}
},
"chrome": {
"title": "Argentina's diet produces 2,172 kg of CO2 per person a year, the most of 130 countries",
"subtitle": "Kilograms of CO2 per person per year from 11 food types, the 20 highest of 130 countries (no year stated)"
}
};
</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 = [/* 20 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "bar",
"encoding": {
"x": {
"field": "kgCo2",
"type": "quantitative",
"axis": {
"title": "kg CO2 per person per year",
"format": ",.0f"
}
},
"y": {
"field": "country",
"type": "nominal",
"sort": "-x"
}
},
"labels": {
"density": "none"
},
"theme": {
"colors": {
"categorical": [
{
"light": "#0e7490",
"dark": "#22a3c4"
}
]
}
},
"chrome": {
"title": "Argentina's diet produces 2,172 kg of CO2 per person a year, the most of 130 countries",
"subtitle": "Kilograms of CO2 per person per year from 11 food types, the 20 highest of 130 countries (no year stated)"
}
};
const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);
As lollipops, each value is a dot at the end of a thin line, and the dots are what the reader compares. The ranking is the same and easier to scan with less fill around it.
Made with OpenChart. How to build this lollipop chart
{
"mark": "lollipop",
"data": [
{
"country": "Argentina",
"kgCo2": 2172.4
},
{
"country": "Australia",
"kgCo2": 1938.7
},
{
"country": "Albania",
"kgCo2": 1777.9
},
{
"country": "New Zealand",
"kgCo2": 1751
},
{
"country": "Iceland",
"kgCo2": 1731.4
},
{
"country": "United States",
"kgCo2": 1718.9
},
// … 14 more rows; Copy includes them
],
"encoding": {
"x": {
"field": "kgCo2",
"type": "quantitative",
"axis": {
"title": "kg CO2 per person per year",
"format": ",.0f"
}
},
"y": {
"field": "country",
"type": "nominal",
"sort": "-x"
}
},
"theme": {
"colors": {
"categorical": [
{
"light": "#0e7490",
"dark": "#22a3c4"
}
]
}
},
"chrome": {
"title": "Argentina's diet produces 2,172 kg of CO2 per person a year, the most of 130 countries",
"subtitle": "Kilograms of CO2 per person per year from 11 food types, the 20 highest of 130 countries (no year stated)"
}
}import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 20 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "lollipop",
"encoding": {
"x": {
"field": "kgCo2",
"type": "quantitative",
"axis": {
"title": "kg CO2 per person per year",
"format": ",.0f"
}
},
"y": {
"field": "country",
"type": "nominal",
"sort": "-x"
}
},
"theme": {
"colors": {
"categorical": [
{
"light": "#0e7490",
"dark": "#22a3c4"
}
]
}
},
"chrome": {
"title": "Argentina's diet produces 2,172 kg of CO2 per person a year, the most of 130 countries",
"subtitle": "Kilograms of CO2 per person per year from 11 food types, the 20 highest of 130 countries (no year stated)"
}
};
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 = [/* 20 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "lollipop",
"encoding": {
"x": {
"field": "kgCo2",
"type": "quantitative",
"axis": {
"title": "kg CO2 per person per year",
"format": ",.0f"
}
},
"y": {
"field": "country",
"type": "nominal",
"sort": "-x"
}
},
"theme": {
"colors": {
"categorical": [
{
"light": "#0e7490",
"dark": "#22a3c4"
}
]
}
},
"chrome": {
"title": "Argentina's diet produces 2,172 kg of CO2 per person a year, the most of 130 countries",
"subtitle": "Kilograms of CO2 per person per year from 11 food types, the 20 highest of 130 countries (no year stated)"
}
};
</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 = [/* 20 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "lollipop",
"encoding": {
"x": {
"field": "kgCo2",
"type": "quantitative",
"axis": {
"title": "kg CO2 per person per year",
"format": ",.0f"
}
},
"y": {
"field": "country",
"type": "nominal",
"sort": "-x"
}
},
"theme": {
"colors": {
"categorical": [
{
"light": "#0e7490",
"dark": "#22a3c4"
}
]
}
},
"chrome": {
"title": "Argentina's diet produces 2,172 kg of CO2 per person a year, the most of 130 countries",
"subtitle": "Kilograms of CO2 per person per year from 11 food types, the 20 highest of 130 countries (no year stated)"
}
};
</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 = [/* 20 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "lollipop",
"encoding": {
"x": {
"field": "kgCo2",
"type": "quantitative",
"axis": {
"title": "kg CO2 per person per year",
"format": ",.0f"
}
},
"y": {
"field": "country",
"type": "nominal",
"sort": "-x"
}
},
"theme": {
"colors": {
"categorical": [
{
"light": "#0e7490",
"dark": "#22a3c4"
}
]
}
},
"chrome": {
"title": "Argentina's diet produces 2,172 kg of CO2 per person a year, the most of 130 countries",
"subtitle": "Kilograms of CO2 per person per year from 11 food types, the 20 highest of 130 countries (no year stated)"
}
};
const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);
The dataset gives no year and no original source. Each value adds up the CO2 from a country’s average consumption of 11 food types, so it describes diets in general rather than any one market.
Starting the axis at zero
A reader judges a lollipop by the length of its stem, the same way they judge a bar. Cut the axis above zero and the lengths stop matching the values. Median weekly earnings run from $738 for adults without a high school diploma to $2,363 for those with a professional degree, a gap of 3.2 times. Start the axis at $600 and the stems measure $138 and $1,763, so the top one is 12.8 times the bottom one.
Made with OpenChart. How to build this lollipop chart
{
"mark": "lollipop",
"data": [
{
"education": "Professional degree",
"weeklyEarnings": 2363
},
{
"education": "Doctoral degree",
"weeklyEarnings": 2278
},
{
"education": "Master's degree",
"weeklyEarnings": 1840
},
{
"education": "Bachelor's degree",
"weeklyEarnings": 1543
},
{
"education": "Associate's degree",
"weeklyEarnings": 1099
},
{
"education": "Some college",
"weeklyEarnings": 1020
},
{
"education": "High school diploma",
"weeklyEarnings": 930
},
{
"education": "Less than high school",
"weeklyEarnings": 738
}
],
"encoding": {
"x": {
"field": "weeklyEarnings",
"type": "quantitative",
"scale": {
"zero": false,
"domain": [
600,
2400
]
},
"axis": {
"title": "Median weekly earnings ($)",
"format": "$,.0f",
"values": [
600,
1200,
1800
]
}
},
"y": {
"field": "education",
"type": "nominal",
"sort": "-x"
}
},
"theme": {
"colors": {
"categorical": [
{
"light": "#0e7490",
"dark": "#22a3c4"
}
]
}
},
"chrome": {
"title": "An axis from $600 makes a 3.2-times gap look like 12.8 times",
"subtitle": "Median usual weekly earnings by educational attainment, 2024 ($)"
}
}import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 8 rows, as in the Spec tab; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "lollipop",
"encoding": {
"x": {
"field": "weeklyEarnings",
"type": "quantitative",
"scale": {
"zero": false,
"domain": [
600,
2400
]
},
"axis": {
"title": "Median weekly earnings ($)",
"format": "$,.0f",
"values": [
600,
1200,
1800
]
}
},
"y": {
"field": "education",
"type": "nominal",
"sort": "-x"
}
},
"theme": {
"colors": {
"categorical": [
{
"light": "#0e7490",
"dark": "#22a3c4"
}
]
}
},
"chrome": {
"title": "An axis from $600 makes a 3.2-times gap look like 12.8 times",
"subtitle": "Median usual weekly earnings by educational attainment, 2024 ($)"
}
};
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 = [/* 8 rows, as in the Spec tab; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "lollipop",
"encoding": {
"x": {
"field": "weeklyEarnings",
"type": "quantitative",
"scale": {
"zero": false,
"domain": [
600,
2400
]
},
"axis": {
"title": "Median weekly earnings ($)",
"format": "$,.0f",
"values": [
600,
1200,
1800
]
}
},
"y": {
"field": "education",
"type": "nominal",
"sort": "-x"
}
},
"theme": {
"colors": {
"categorical": [
{
"light": "#0e7490",
"dark": "#22a3c4"
}
]
}
},
"chrome": {
"title": "An axis from $600 makes a 3.2-times gap look like 12.8 times",
"subtitle": "Median usual weekly earnings by educational attainment, 2024 ($)"
}
};
</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 = [/* 8 rows, as in the Spec tab; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "lollipop",
"encoding": {
"x": {
"field": "weeklyEarnings",
"type": "quantitative",
"scale": {
"zero": false,
"domain": [
600,
2400
]
},
"axis": {
"title": "Median weekly earnings ($)",
"format": "$,.0f",
"values": [
600,
1200,
1800
]
}
},
"y": {
"field": "education",
"type": "nominal",
"sort": "-x"
}
},
"theme": {
"colors": {
"categorical": [
{
"light": "#0e7490",
"dark": "#22a3c4"
}
]
}
},
"chrome": {
"title": "An axis from $600 makes a 3.2-times gap look like 12.8 times",
"subtitle": "Median usual weekly earnings by educational attainment, 2024 ($)"
}
};
</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 = [/* 8 rows, as in the Spec tab; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "lollipop",
"encoding": {
"x": {
"field": "weeklyEarnings",
"type": "quantitative",
"scale": {
"zero": false,
"domain": [
600,
2400
]
},
"axis": {
"title": "Median weekly earnings ($)",
"format": "$,.0f",
"values": [
600,
1200,
1800
]
}
},
"y": {
"field": "education",
"type": "nominal",
"sort": "-x"
}
},
"theme": {
"colors": {
"categorical": [
{
"light": "#0e7490",
"dark": "#22a3c4"
}
]
}
},
"chrome": {
"title": "An axis from $600 makes a 3.2-times gap look like 12.8 times",
"subtitle": "Median usual weekly earnings by educational attainment, 2024 ($)"
}
};
const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);
This is the same mistake as a truncated bar, covered in when bar charts must start at zero. Thin stems make it easier to miss, because a lollipop doesn’t look like a filled shape that has been cut off.
Dot plots
If the point is where values sit rather than how long they are, drop the stems. A dot plot encodes position only, so the same axis from $600 is fair here, because the reader compares where the dots fall and no length stands for a value.
Made with OpenChart. How to build this scatter plot
{
"mark": {
"type": "point",
"trendline": false
},
"data": [
{
"education": "Professional degree",
"weeklyEarnings": 2363
},
{
"education": "Doctoral degree",
"weeklyEarnings": 2278
},
{
"education": "Master's degree",
"weeklyEarnings": 1840
},
{
"education": "Bachelor's degree",
"weeklyEarnings": 1543
},
{
"education": "Associate's degree",
"weeklyEarnings": 1099
},
{
"education": "Some college",
"weeklyEarnings": 1020
},
{
"education": "High school diploma",
"weeklyEarnings": 930
},
{
"education": "Less than high school",
"weeklyEarnings": 738
}
],
"encoding": {
"x": {
"field": "weeklyEarnings",
"type": "quantitative",
"scale": {
"zero": false,
"domain": [
600,
2400
]
},
"axis": {
"title": "Median weekly earnings ($)",
"format": "$,.0f",
"values": [
600,
1200,
1800
]
}
},
"y": {
"field": "education",
"type": "nominal",
"sort": "-x",
"axis": {
"values": [
"Professional degree",
"Doctoral degree",
"Master's degree",
"Bachelor's degree",
"Associate's degree",
"Some college",
"High school diploma",
"Less than high school"
]
}
}
},
"theme": {
"colors": {
"categorical": [
{
"light": "#0e7490",
"dark": "#22a3c4"
}
]
}
},
"chrome": {
"title": "Median weekly earnings range from $738 to $2,363 by education",
"subtitle": "Median usual weekly earnings by educational attainment, 2024 ($)"
}
}import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 8 rows, as in the Spec tab; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": {
"type": "point",
"trendline": false
},
"encoding": {
"x": {
"field": "weeklyEarnings",
"type": "quantitative",
"scale": {
"zero": false,
"domain": [
600,
2400
]
},
"axis": {
"title": "Median weekly earnings ($)",
"format": "$,.0f",
"values": [
600,
1200,
1800
]
}
},
"y": {
"field": "education",
"type": "nominal",
"sort": "-x",
"axis": {
"values": [
"Professional degree",
"Doctoral degree",
"Master's degree",
"Bachelor's degree",
"Associate's degree",
"Some college",
"High school diploma",
"Less than high school"
]
}
}
},
"theme": {
"colors": {
"categorical": [
{
"light": "#0e7490",
"dark": "#22a3c4"
}
]
}
},
"chrome": {
"title": "Median weekly earnings range from $738 to $2,363 by education",
"subtitle": "Median usual weekly earnings by educational attainment, 2024 ($)"
}
};
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 = [/* 8 rows, as in the Spec tab; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": {
"type": "point",
"trendline": false
},
"encoding": {
"x": {
"field": "weeklyEarnings",
"type": "quantitative",
"scale": {
"zero": false,
"domain": [
600,
2400
]
},
"axis": {
"title": "Median weekly earnings ($)",
"format": "$,.0f",
"values": [
600,
1200,
1800
]
}
},
"y": {
"field": "education",
"type": "nominal",
"sort": "-x",
"axis": {
"values": [
"Professional degree",
"Doctoral degree",
"Master's degree",
"Bachelor's degree",
"Associate's degree",
"Some college",
"High school diploma",
"Less than high school"
]
}
}
},
"theme": {
"colors": {
"categorical": [
{
"light": "#0e7490",
"dark": "#22a3c4"
}
]
}
},
"chrome": {
"title": "Median weekly earnings range from $738 to $2,363 by education",
"subtitle": "Median usual weekly earnings by educational attainment, 2024 ($)"
}
};
</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 = [/* 8 rows, as in the Spec tab; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": {
"type": "point",
"trendline": false
},
"encoding": {
"x": {
"field": "weeklyEarnings",
"type": "quantitative",
"scale": {
"zero": false,
"domain": [
600,
2400
]
},
"axis": {
"title": "Median weekly earnings ($)",
"format": "$,.0f",
"values": [
600,
1200,
1800
]
}
},
"y": {
"field": "education",
"type": "nominal",
"sort": "-x",
"axis": {
"values": [
"Professional degree",
"Doctoral degree",
"Master's degree",
"Bachelor's degree",
"Associate's degree",
"Some college",
"High school diploma",
"Less than high school"
]
}
}
},
"theme": {
"colors": {
"categorical": [
{
"light": "#0e7490",
"dark": "#22a3c4"
}
]
}
},
"chrome": {
"title": "Median weekly earnings range from $738 to $2,363 by education",
"subtitle": "Median usual weekly earnings by educational attainment, 2024 ($)"
}
};
</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 = [/* 8 rows, as in the Spec tab; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": {
"type": "point",
"trendline": false
},
"encoding": {
"x": {
"field": "weeklyEarnings",
"type": "quantitative",
"scale": {
"zero": false,
"domain": [
600,
2400
]
},
"axis": {
"title": "Median weekly earnings ($)",
"format": "$,.0f",
"values": [
600,
1200,
1800
]
}
},
"y": {
"field": "education",
"type": "nominal",
"sort": "-x",
"axis": {
"values": [
"Professional degree",
"Doctoral degree",
"Master's degree",
"Bachelor's degree",
"Associate's degree",
"Some college",
"High school diploma",
"Less than high school"
]
}
}
},
"theme": {
"colors": {
"categorical": [
{
"light": "#0e7490",
"dark": "#22a3c4"
}
]
}
},
"chrome": {
"title": "Median weekly earnings range from $738 to $2,363 by education",
"subtitle": "Median usual weekly earnings by educational attainment, 2024 ($)"
}
};
const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);
When plain bars are better
With eight categories and values worth printing, bars win. The earnings chart below puts each dollar figure inside its bar, and the fill makes the gap between a high school diploma ($930) and a bachelor’s degree ($1,543) read as a quantity.
Made with OpenChart. How to build this bar chart
{
"mark": "bar",
"data": [
{
"education": "Professional degree",
"weeklyEarnings": 2363
},
{
"education": "Doctoral degree",
"weeklyEarnings": 2278
},
{
"education": "Master's degree",
"weeklyEarnings": 1840
},
{
"education": "Bachelor's degree",
"weeklyEarnings": 1543
},
{
"education": "Associate's degree",
"weeklyEarnings": 1099
},
{
"education": "Some college",
"weeklyEarnings": 1020
},
{
"education": "High school diploma",
"weeklyEarnings": 930
},
{
"education": "Less than high school",
"weeklyEarnings": 738
}
],
"encoding": {
"x": {
"field": "weeklyEarnings",
"type": "quantitative",
"axis": {
"title": "Median weekly earnings ($)",
"format": "$,.0f"
}
},
"y": {
"field": "education",
"type": "nominal",
"sort": "-x"
}
},
"labels": {
"density": "all",
"format": "$,.0f"
},
"theme": {
"colors": {
"categorical": [
{
"light": "#0e7490",
"dark": "#22a3c4"
}
]
}
},
"chrome": {
"title": "Median weekly earnings range from $738 to $2,363 by education",
"subtitle": "Median usual weekly earnings by educational attainment, 2024 ($)"
}
}import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 8 rows, as in the Spec tab; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "bar",
"encoding": {
"x": {
"field": "weeklyEarnings",
"type": "quantitative",
"axis": {
"title": "Median weekly earnings ($)",
"format": "$,.0f"
}
},
"y": {
"field": "education",
"type": "nominal",
"sort": "-x"
}
},
"labels": {
"density": "all",
"format": "$,.0f"
},
"theme": {
"colors": {
"categorical": [
{
"light": "#0e7490",
"dark": "#22a3c4"
}
]
}
},
"chrome": {
"title": "Median weekly earnings range from $738 to $2,363 by education",
"subtitle": "Median usual weekly earnings by educational attainment, 2024 ($)"
}
};
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 = [/* 8 rows, as in the Spec tab; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "bar",
"encoding": {
"x": {
"field": "weeklyEarnings",
"type": "quantitative",
"axis": {
"title": "Median weekly earnings ($)",
"format": "$,.0f"
}
},
"y": {
"field": "education",
"type": "nominal",
"sort": "-x"
}
},
"labels": {
"density": "all",
"format": "$,.0f"
},
"theme": {
"colors": {
"categorical": [
{
"light": "#0e7490",
"dark": "#22a3c4"
}
]
}
},
"chrome": {
"title": "Median weekly earnings range from $738 to $2,363 by education",
"subtitle": "Median usual weekly earnings by educational attainment, 2024 ($)"
}
};
</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 = [/* 8 rows, as in the Spec tab; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "bar",
"encoding": {
"x": {
"field": "weeklyEarnings",
"type": "quantitative",
"axis": {
"title": "Median weekly earnings ($)",
"format": "$,.0f"
}
},
"y": {
"field": "education",
"type": "nominal",
"sort": "-x"
}
},
"labels": {
"density": "all",
"format": "$,.0f"
},
"theme": {
"colors": {
"categorical": [
{
"light": "#0e7490",
"dark": "#22a3c4"
}
]
}
},
"chrome": {
"title": "Median weekly earnings range from $738 to $2,363 by education",
"subtitle": "Median usual weekly earnings by educational attainment, 2024 ($)"
}
};
</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 = [/* 8 rows, as in the Spec tab; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "bar",
"encoding": {
"x": {
"field": "weeklyEarnings",
"type": "quantitative",
"axis": {
"title": "Median weekly earnings ($)",
"format": "$,.0f"
}
},
"y": {
"field": "education",
"type": "nominal",
"sort": "-x"
}
},
"labels": {
"density": "all",
"format": "$,.0f"
},
"theme": {
"colors": {
"categorical": [
{
"light": "#0e7490",
"dark": "#22a3c4"
}
]
}
},
"chrome": {
"title": "Median weekly earnings range from $738 to $2,363 by education",
"subtitle": "Median usual weekly earnings by educational attainment, 2024 ($)"
}
};
const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);
A short list gains nothing from having less ink. I would use bars for about ten categories or fewer and a lollipop for a longer list.
Bars can also stack and group, and a lollipop can’t. Give a lollipop a color field and it becomes a dumbbell instead, which joins the lowest and highest value in each category for any number of series. For a short ranked list inside a dashboard card, a bar list drops the axis and puts each label, bar and value in one compact row.
The spec
A lollipop uses the same encoding as a bar chart: the value on x as a quantitative field and the category on y as a nominal one. Setting mark to "lollipop" instead of "bar" is the whole change, and sort on y puts the categories in value order.
The trimmed chart adds scale: { zero: false, domain: [600, 2400] } on x, with axis.values starting at 600 so the cut shows on the axis. Leave that out of real lollipop charts. The dot plot keeps the same axis and sets mark: { type: "point", trendline: false }. Lollipop and circle marks always draw stems, and a point mark left with its default trend line fits a regression line through the dots, which means nothing across categories.
Negative values and the dumbbell form are on the lollipop page.