Scatter
Plot two numeric fields against each other to find correlation, clusters and outliers, then add color, direct labels, a reference line and a log axis.
A scatter chart places one dot per row at the position of two numbers, so a reader can see whether they move together, which rows cluster and which sit apart. Reach for it when the question is how one measure relates to another.
Add a third number and it becomes a bubble chart. When both fields are categories, a heatmap fits better, and when the x field is time, a line chart shows the trend directly.
A basic scatter
Set mark to "point" and put one quantitative field on each of x and y. A tooltip channel lists the fields shown on hover. A scatter also draws a fitted trend line by default, which the trendlines page covers.
{
"mark": "point",
"data": [
{
"country": "Singapore",
"spending": 14.5,
"math": 575
},
{
"country": "Japan",
"spending": 10.1,
"math": 536
},
{
"country": "South Korea",
"spending": 12.2,
"math": 527
},
{
"country": "Estonia",
"spending": 8.4,
"math": 510
},
{
"country": "Switzerland",
"spending": 17.8,
"math": 508
},
{
"country": "Canada",
"spending": 12.4,
"math": 497
},
// … 16 more rows; Copy includes them
],
"encoding": {
"x": {
"field": "spending",
"type": "quantitative",
"axis": {
"title": "Spending per student ($K, PPP)"
}
},
"y": {
"field": "math",
"type": "quantitative",
"axis": {
"title": "PISA math score"
}
},
"tooltip": [
{
"field": "country",
"type": "nominal",
"title": "Country"
},
{
"field": "spending",
"type": "quantitative",
"title": "Spending ($K)"
},
{
"field": "math",
"type": "quantitative",
"title": "Math score"
}
]
},
"chrome": {
"title": "Switzerland spends the most per student; Singapore scores highest",
"subtitle": "Cumulative per-student spending vs. PISA 2022 math performance, OECD countries"
}
}import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 22 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "point",
"encoding": {
"x": {
"field": "spending",
"type": "quantitative",
"axis": {
"title": "Spending per student ($K, PPP)"
}
},
"y": {
"field": "math",
"type": "quantitative",
"axis": {
"title": "PISA math score"
}
},
"tooltip": [
{
"field": "country",
"type": "nominal",
"title": "Country"
},
{
"field": "spending",
"type": "quantitative",
"title": "Spending ($K)"
},
{
"field": "math",
"type": "quantitative",
"title": "Math score"
}
]
},
"chrome": {
"title": "Switzerland spends the most per student; Singapore scores highest",
"subtitle": "Cumulative per-student spending vs. PISA 2022 math performance, OECD countries"
}
};
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 = [/* 22 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "point",
"encoding": {
"x": {
"field": "spending",
"type": "quantitative",
"axis": {
"title": "Spending per student ($K, PPP)"
}
},
"y": {
"field": "math",
"type": "quantitative",
"axis": {
"title": "PISA math score"
}
},
"tooltip": [
{
"field": "country",
"type": "nominal",
"title": "Country"
},
{
"field": "spending",
"type": "quantitative",
"title": "Spending ($K)"
},
{
"field": "math",
"type": "quantitative",
"title": "Math score"
}
]
},
"chrome": {
"title": "Switzerland spends the most per student; Singapore scores highest",
"subtitle": "Cumulative per-student spending vs. PISA 2022 math performance, OECD countries"
}
};
</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 = [/* 22 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "point",
"encoding": {
"x": {
"field": "spending",
"type": "quantitative",
"axis": {
"title": "Spending per student ($K, PPP)"
}
},
"y": {
"field": "math",
"type": "quantitative",
"axis": {
"title": "PISA math score"
}
},
"tooltip": [
{
"field": "country",
"type": "nominal",
"title": "Country"
},
{
"field": "spending",
"type": "quantitative",
"title": "Spending ($K)"
},
{
"field": "math",
"type": "quantitative",
"title": "Math score"
}
]
},
"chrome": {
"title": "Switzerland spends the most per student; Singapore scores highest",
"subtitle": "Cumulative per-student spending vs. PISA 2022 math performance, OECD countries"
}
};
</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 = [/* 22 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "point",
"encoding": {
"x": {
"field": "spending",
"type": "quantitative",
"axis": {
"title": "Spending per student ($K, PPP)"
}
},
"y": {
"field": "math",
"type": "quantitative",
"axis": {
"title": "PISA math score"
}
},
"tooltip": [
{
"field": "country",
"type": "nominal",
"title": "Country"
},
{
"field": "spending",
"type": "quantitative",
"title": "Spending ($K)"
},
{
"field": "math",
"type": "quantitative",
"title": "Math score"
}
]
},
"chrome": {
"title": "Switzerland spends the most per student; Singapore scores highest",
"subtitle": "Cumulative per-student spending vs. PISA 2022 math performance, OECD countries"
}
};
const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);
Direct labels
Text annotations name the notable points on the chart, so a reader does not need to hover to find them. A refline marks a benchmark, here the OECD average. Anchor each label to the side of its point that has room.
{
"mark": "point",
"data": [
{
"country": "Singapore",
"spending": 14.5,
"math": 575
},
{
"country": "Japan",
"spending": 10.1,
"math": 536
},
{
"country": "South Korea",
"spending": 12.2,
"math": 527
},
{
"country": "Estonia",
"spending": 8.4,
"math": 510
},
{
"country": "Switzerland",
"spending": 17.8,
"math": 508
},
{
"country": "Canada",
"spending": 12.4,
"math": 497
},
// … 16 more rows; Copy includes them
],
"encoding": {
"x": {
"field": "spending",
"type": "quantitative",
"axis": {
"title": "Spending per student ($K, PPP)"
}
},
"y": {
"field": "math",
"type": "quantitative",
"axis": {
"title": "PISA math score"
}
}
},
"annotations": [
{
"type": "text",
"x": 14.5,
"y": 575,
"text": "Singapore",
"anchor": "left",
"fontSize": 10,
"dot": false
},
{
"type": "text",
"x": 14.3,
"y": 465,
"text": "United States",
"anchor": "right",
"fontSize": 10,
"dot": false
},
{
"type": "text",
"x": 8.4,
"y": 510,
"text": "Estonia",
"anchor": "left",
"fontSize": 10,
"dot": false
},
{
"type": "refline",
"y": 472,
"label": "OECD avg",
"style": "dashed",
"stroke": "#64748b"
}
],
"chrome": {
"title": "The US spends about as much as Singapore and scores 110 points lower",
"subtitle": "Cumulative per-student spending vs. PISA 2022 math performance, OECD countries"
}
}import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 22 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "point",
"encoding": {
"x": {
"field": "spending",
"type": "quantitative",
"axis": {
"title": "Spending per student ($K, PPP)"
}
},
"y": {
"field": "math",
"type": "quantitative",
"axis": {
"title": "PISA math score"
}
}
},
"annotations": [
{
"type": "text",
"x": 14.5,
"y": 575,
"text": "Singapore",
"anchor": "left",
"fontSize": 10,
"dot": false
},
{
"type": "text",
"x": 14.3,
"y": 465,
"text": "United States",
"anchor": "right",
"fontSize": 10,
"dot": false
},
{
"type": "text",
"x": 8.4,
"y": 510,
"text": "Estonia",
"anchor": "left",
"fontSize": 10,
"dot": false
},
{
"type": "refline",
"y": 472,
"label": "OECD avg",
"style": "dashed",
"stroke": "#64748b"
}
],
"chrome": {
"title": "The US spends about as much as Singapore and scores 110 points lower",
"subtitle": "Cumulative per-student spending vs. PISA 2022 math performance, OECD countries"
}
};
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 = [/* 22 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "point",
"encoding": {
"x": {
"field": "spending",
"type": "quantitative",
"axis": {
"title": "Spending per student ($K, PPP)"
}
},
"y": {
"field": "math",
"type": "quantitative",
"axis": {
"title": "PISA math score"
}
}
},
"annotations": [
{
"type": "text",
"x": 14.5,
"y": 575,
"text": "Singapore",
"anchor": "left",
"fontSize": 10,
"dot": false
},
{
"type": "text",
"x": 14.3,
"y": 465,
"text": "United States",
"anchor": "right",
"fontSize": 10,
"dot": false
},
{
"type": "text",
"x": 8.4,
"y": 510,
"text": "Estonia",
"anchor": "left",
"fontSize": 10,
"dot": false
},
{
"type": "refline",
"y": 472,
"label": "OECD avg",
"style": "dashed",
"stroke": "#64748b"
}
],
"chrome": {
"title": "The US spends about as much as Singapore and scores 110 points lower",
"subtitle": "Cumulative per-student spending vs. PISA 2022 math performance, OECD countries"
}
};
</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 = [/* 22 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "point",
"encoding": {
"x": {
"field": "spending",
"type": "quantitative",
"axis": {
"title": "Spending per student ($K, PPP)"
}
},
"y": {
"field": "math",
"type": "quantitative",
"axis": {
"title": "PISA math score"
}
}
},
"annotations": [
{
"type": "text",
"x": 14.5,
"y": 575,
"text": "Singapore",
"anchor": "left",
"fontSize": 10,
"dot": false
},
{
"type": "text",
"x": 14.3,
"y": 465,
"text": "United States",
"anchor": "right",
"fontSize": 10,
"dot": false
},
{
"type": "text",
"x": 8.4,
"y": 510,
"text": "Estonia",
"anchor": "left",
"fontSize": 10,
"dot": false
},
{
"type": "refline",
"y": 472,
"label": "OECD avg",
"style": "dashed",
"stroke": "#64748b"
}
],
"chrome": {
"title": "The US spends about as much as Singapore and scores 110 points lower",
"subtitle": "Cumulative per-student spending vs. PISA 2022 math performance, OECD countries"
}
};
</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 = [/* 22 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "point",
"encoding": {
"x": {
"field": "spending",
"type": "quantitative",
"axis": {
"title": "Spending per student ($K, PPP)"
}
},
"y": {
"field": "math",
"type": "quantitative",
"axis": {
"title": "PISA math score"
}
}
},
"annotations": [
{
"type": "text",
"x": 14.5,
"y": 575,
"text": "Singapore",
"anchor": "left",
"fontSize": 10,
"dot": false
},
{
"type": "text",
"x": 14.3,
"y": 465,
"text": "United States",
"anchor": "right",
"fontSize": 10,
"dot": false
},
{
"type": "text",
"x": 8.4,
"y": 510,
"text": "Estonia",
"anchor": "left",
"fontSize": 10,
"dot": false
},
{
"type": "refline",
"y": 472,
"label": "OECD avg",
"style": "dashed",
"stroke": "#64748b"
}
],
"chrome": {
"title": "The US spends about as much as Singapore and scores 110 points lower",
"subtitle": "Cumulative per-student spending vs. PISA 2022 math performance, OECD countries"
}
};
const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);
Color groups
A categorical color channel splits the cloud into series. Setting scale.domain on each axis fixes the plot window to a range you choose.
{
"mark": "point",
"data": [
{
"city": "Zurich",
"cost": 131,
"quality": 98,
"region": "Europe"
},
{
"city": "Vienna",
"cost": 79,
"quality": 97,
"region": "Europe"
},
{
"city": "Geneva",
"cost": 124,
"quality": 96,
"region": "Europe"
},
{
"city": "Copenhagen",
"cost": 89,
"quality": 95,
"region": "Europe"
},
{
"city": "Singapore",
"cost": 107,
"quality": 93,
"region": "Asia"
},
{
"city": "Sydney",
"cost": 83,
"quality": 92,
"region": "Asia-Pacific"
},
// … 12 more rows; Copy includes them
],
"encoding": {
"x": {
"field": "cost",
"type": "quantitative",
"axis": {
"title": "Cost of living index"
},
"scale": {
"domain": [
35,
140
]
}
},
"y": {
"field": "quality",
"type": "quantitative",
"axis": {
"title": "Quality of living index"
},
"scale": {
"domain": [
68,
100
]
}
},
"color": {
"field": "region",
"type": "nominal"
},
"tooltip": [
{
"field": "city",
"type": "nominal",
"title": "City"
},
{
"field": "cost",
"type": "quantitative",
"title": "Cost index"
},
{
"field": "quality",
"type": "quantitative",
"title": "Quality index"
},
{
"field": "region",
"type": "nominal",
"title": "Region"
}
]
},
"chrome": {
"title": "Vienna and Montreal rate higher than New York and cost less",
"subtitle": "Cost of living vs. quality of living in global cities, 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 = [/* 18 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "point",
"encoding": {
"x": {
"field": "cost",
"type": "quantitative",
"axis": {
"title": "Cost of living index"
},
"scale": {
"domain": [
35,
140
]
}
},
"y": {
"field": "quality",
"type": "quantitative",
"axis": {
"title": "Quality of living index"
},
"scale": {
"domain": [
68,
100
]
}
},
"color": {
"field": "region",
"type": "nominal"
},
"tooltip": [
{
"field": "city",
"type": "nominal",
"title": "City"
},
{
"field": "cost",
"type": "quantitative",
"title": "Cost index"
},
{
"field": "quality",
"type": "quantitative",
"title": "Quality index"
},
{
"field": "region",
"type": "nominal",
"title": "Region"
}
]
},
"chrome": {
"title": "Vienna and Montreal rate higher than New York and cost less",
"subtitle": "Cost of living vs. quality of living in global cities, 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 = [/* 18 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "point",
"encoding": {
"x": {
"field": "cost",
"type": "quantitative",
"axis": {
"title": "Cost of living index"
},
"scale": {
"domain": [
35,
140
]
}
},
"y": {
"field": "quality",
"type": "quantitative",
"axis": {
"title": "Quality of living index"
},
"scale": {
"domain": [
68,
100
]
}
},
"color": {
"field": "region",
"type": "nominal"
},
"tooltip": [
{
"field": "city",
"type": "nominal",
"title": "City"
},
{
"field": "cost",
"type": "quantitative",
"title": "Cost index"
},
{
"field": "quality",
"type": "quantitative",
"title": "Quality index"
},
{
"field": "region",
"type": "nominal",
"title": "Region"
}
]
},
"chrome": {
"title": "Vienna and Montreal rate higher than New York and cost less",
"subtitle": "Cost of living vs. quality of living in global cities, 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 = [/* 18 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "point",
"encoding": {
"x": {
"field": "cost",
"type": "quantitative",
"axis": {
"title": "Cost of living index"
},
"scale": {
"domain": [
35,
140
]
}
},
"y": {
"field": "quality",
"type": "quantitative",
"axis": {
"title": "Quality of living index"
},
"scale": {
"domain": [
68,
100
]
}
},
"color": {
"field": "region",
"type": "nominal"
},
"tooltip": [
{
"field": "city",
"type": "nominal",
"title": "City"
},
{
"field": "cost",
"type": "quantitative",
"title": "Cost index"
},
{
"field": "quality",
"type": "quantitative",
"title": "Quality index"
},
{
"field": "region",
"type": "nominal",
"title": "Region"
}
]
},
"chrome": {
"title": "Vienna and Montreal rate higher than New York and cost less",
"subtitle": "Cost of living vs. quality of living in global cities, 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 = [/* 18 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "point",
"encoding": {
"x": {
"field": "cost",
"type": "quantitative",
"axis": {
"title": "Cost of living index"
},
"scale": {
"domain": [
35,
140
]
}
},
"y": {
"field": "quality",
"type": "quantitative",
"axis": {
"title": "Quality of living index"
},
"scale": {
"domain": [
68,
100
]
}
},
"color": {
"field": "region",
"type": "nominal"
},
"tooltip": [
{
"field": "city",
"type": "nominal",
"title": "City"
},
{
"field": "cost",
"type": "quantitative",
"title": "Cost index"
},
{
"field": "quality",
"type": "quantitative",
"title": "Quality index"
},
{
"field": "region",
"type": "nominal",
"title": "Region"
}
]
},
"chrome": {
"title": "Vienna and Montreal rate higher than New York and cost less",
"subtitle": "Cost of living vs. quality of living in global cities, 2024"
}
};
const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);
A log axis
scale: { type: "log" } spaces the axis by orders of magnitude. It suits a field like GDP per capita that spans a wide range.
{
"mark": "point",
"data": [
{
"country": "United States",
"gdpPerCapita": 63544,
"lifeExpectancy": 77.3,
"region": "Americas",
"pop": 331
},
{
"country": "Canada",
"gdpPerCapita": 43242,
"lifeExpectancy": 82.2,
"region": "Americas",
"pop": 38
},
{
"country": "Brazil",
"gdpPerCapita": 6797,
"lifeExpectancy": 75.9,
"region": "Americas",
"pop": 213
},
{
"country": "Mexico",
"gdpPerCapita": 8347,
"lifeExpectancy": 75.1,
"region": "Americas",
"pop": 130
},
{
"country": "Argentina",
"gdpPerCapita": 8442,
"lifeExpectancy": 76.5,
"region": "Americas",
"pop": 45
},
{
"country": "Germany",
"gdpPerCapita": 45724,
"lifeExpectancy": 81,
"region": "Europe",
"pop": 83
},
// … 14 more rows; Copy includes them
],
"encoding": {
"x": {
"field": "gdpPerCapita",
"type": "quantitative",
"scale": {
"type": "log"
},
"axis": {
"title": "GDP per capita (USD, log scale)",
"format": "$.2~s"
}
},
"y": {
"field": "lifeExpectancy",
"type": "quantitative",
"axis": {
"title": "Life expectancy (years)"
}
},
"color": {
"field": "region",
"type": "nominal"
}
},
"chrome": {
"title": "A log axis spreads out the poorest countries",
"subtitle": "GDP per capita vs. life expectancy, 2022"
}
}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": "point",
"encoding": {
"x": {
"field": "gdpPerCapita",
"type": "quantitative",
"scale": {
"type": "log"
},
"axis": {
"title": "GDP per capita (USD, log scale)",
"format": "$.2~s"
}
},
"y": {
"field": "lifeExpectancy",
"type": "quantitative",
"axis": {
"title": "Life expectancy (years)"
}
},
"color": {
"field": "region",
"type": "nominal"
}
},
"chrome": {
"title": "A log axis spreads out the poorest countries",
"subtitle": "GDP per capita vs. life expectancy, 2022"
}
};
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": "point",
"encoding": {
"x": {
"field": "gdpPerCapita",
"type": "quantitative",
"scale": {
"type": "log"
},
"axis": {
"title": "GDP per capita (USD, log scale)",
"format": "$.2~s"
}
},
"y": {
"field": "lifeExpectancy",
"type": "quantitative",
"axis": {
"title": "Life expectancy (years)"
}
},
"color": {
"field": "region",
"type": "nominal"
}
},
"chrome": {
"title": "A log axis spreads out the poorest countries",
"subtitle": "GDP per capita vs. life expectancy, 2022"
}
};
</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": "point",
"encoding": {
"x": {
"field": "gdpPerCapita",
"type": "quantitative",
"scale": {
"type": "log"
},
"axis": {
"title": "GDP per capita (USD, log scale)",
"format": "$.2~s"
}
},
"y": {
"field": "lifeExpectancy",
"type": "quantitative",
"axis": {
"title": "Life expectancy (years)"
}
},
"color": {
"field": "region",
"type": "nominal"
}
},
"chrome": {
"title": "A log axis spreads out the poorest countries",
"subtitle": "GDP per capita vs. life expectancy, 2022"
}
};
</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": "point",
"encoding": {
"x": {
"field": "gdpPerCapita",
"type": "quantitative",
"scale": {
"type": "log"
},
"axis": {
"title": "GDP per capita (USD, log scale)",
"format": "$.2~s"
}
},
"y": {
"field": "lifeExpectancy",
"type": "quantitative",
"axis": {
"title": "Life expectancy (years)"
}
},
"color": {
"field": "region",
"type": "nominal"
}
},
"chrome": {
"title": "A log axis spreads out the poorest countries",
"subtitle": "GDP per capita vs. life expectancy, 2022"
}
};
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 |
"point" draws one dot per row. |
encoding.x, encoding.y |
The two quantitative fields the dot is placed by. |
encoding.color |
Optional. A categorical field that splits the dots into colored series. |
encoding.tooltip |
Optional. The fields listed when a dot is hovered. |
scale.domain |
Fixes the axis range to [min, max]. |
scale.type |
Sets the scale type. "log" gives a logarithmic axis. |
scale.zero |
Whether the axis must include zero. Point marks default to false, so the axis fits the data; set true to anchor at zero. |
annotations |
Text labels and refline entries drawn in data units. |
Related
- Bubble: add a third number as dot size.
- Trendlines: control the fitted line.
- Heatmap: relate two categories through a number.
- Beeswarm: one number per dot, dodged along a lane.
- Line: a trend over time.
- Encoding reference: every channel with its scale and axis settings.