How to make a heatmap in JavaScript
A heatmap colors each cell of a grid by a number. This post builds two, one with a sequential color scale and one with a diverging scale.
OpenChart4 min read
Made with OpenChart. How to build this heatmap
New green cards fell for all six of the largest countries of birth in fiscal 2020, and the total dropped by 31%. In a table of 60 numbers that takes a while to find. In a heatmap, a grid with one category along each side and a cell colored by its number, it is the pale row near the bottom.
A basic heatmap with cell labels
DHS counts new green-card holders (lawful permanent residents) by country of birth and fiscal year in the Yearbook of Immigration Statistics. Here are six countries over ten fiscal years, with the years down the side.
Made with OpenChart. How to build this heatmap
{
"layer": [
{
"mark": "rect",
"data": [
{
"country": "Mexico",
"year": "2014",
"cards": 134
},
{
"country": "India",
"year": "2014",
"cards": 78
},
{
"country": "China",
"year": "2014",
"cards": 76
},
{
"country": "Cuba",
"year": "2014",
"cards": 47
},
{
"country": "Dominican Rep",
"year": "2014",
"cards": 45
},
{
"country": "Philippines",
"year": "2014",
"cards": 50
},
{
"country": "Mexico",
"year": "2015",
"cards": 159
},
{
"country": "India",
"year": "2015",
"cards": 64
},
{
"country": "China",
"year": "2015",
"cards": 75
},
{
"country": "Cuba",
"year": "2015",
"cards": 54
},
{
"country": "Dominican Rep",
"year": "2015",
"cards": 51
},
{
"country": "Philippines",
"year": "2015",
"cards": 56
},
{
"country": "Mexico",
"year": "2016",
"cards": 175
},
{
"country": "India",
"year": "2016",
"cards": 65
},
{
"country": "China",
"year": "2016",
"cards": 82
},
{
"country": "Cuba",
"year": "2016",
"cards": 67
},
{
"country": "Dominican Rep",
"year": "2016",
"cards": 61
},
{
"country": "Philippines",
"year": "2016",
"cards": 53
},
{
"country": "Mexico",
"year": "2017",
"cards": 171
},
{
"country": "India",
"year": "2017",
"cards": 60
},
{
"country": "China",
"year": "2017",
"cards": 72
},
{
"country": "Cuba",
"year": "2017",
"cards": 65
},
{
"country": "Dominican Rep",
"year": "2017",
"cards": 59
},
{
"country": "Philippines",
"year": "2017",
"cards": 49
},
{
"country": "Mexico",
"year": "2018",
"cards": 162
},
{
"country": "India",
"year": "2018",
"cards": 60
},
{
"country": "China",
"year": "2018",
"cards": 65
},
{
"country": "Cuba",
"year": "2018",
"cards": 76
},
{
"country": "Dominican Rep",
"year": "2018",
"cards": 57
},
{
"country": "Philippines",
"year": "2018",
"cards": 47
},
{
"country": "Mexico",
"year": "2019",
"cards": 156
},
{
"country": "India",
"year": "2019",
"cards": 55
},
{
"country": "China",
"year": "2019",
"cards": 62
},
{
"country": "Cuba",
"year": "2019",
"cards": 42
},
{
"country": "Dominican Rep",
"year": "2019",
"cards": 50
},
{
"country": "Philippines",
"year": "2019",
"cards": 46
},
{
"country": "Mexico",
"year": "2020",
"cards": 100
},
{
"country": "India",
"year": "2020",
"cards": 46
},
{
"country": "China",
"year": "2020",
"cards": 41
},
{
"country": "Cuba",
"year": "2020",
"cards": 16
},
{
"country": "Dominican Rep",
"year": "2020",
"cards": 30
},
{
"country": "Philippines",
"year": "2020",
"cards": 25
},
{
"country": "Mexico",
"year": "2021",
"cards": 107
},
{
"country": "India",
"year": "2021",
"cards": 93
},
{
"country": "China",
"year": "2021",
"cards": 50
},
{
"country": "Cuba",
"year": "2021",
"cards": 23
},
{
"country": "Dominican Rep",
"year": "2021",
"cards": 25
},
{
"country": "Philippines",
"year": "2021",
"cards": 28
},
{
"country": "Mexico",
"year": "2022",
"cards": 139
},
{
"country": "India",
"year": "2022",
"cards": 127
},
{
"country": "China",
"year": "2022",
"cards": 68
},
{
"country": "Cuba",
"year": "2022",
"cards": 37
},
{
"country": "Dominican Rep",
"year": "2022",
"cards": 40
},
{
"country": "Philippines",
"year": "2022",
"cards": 36
},
{
"country": "Mexico",
"year": "2023",
"cards": 181
},
{
"country": "India",
"year": "2023",
"cards": 78
},
{
"country": "China",
"year": "2023",
"cards": 59
},
{
"country": "Cuba",
"year": "2023",
"cards": 82
},
{
"country": "Dominican Rep",
"year": "2023",
"cards": 69
},
{
"country": "Philippines",
"year": "2023",
"cards": 49
}
],
"encoding": {
"x": {
"field": "country",
"type": "nominal",
"sort": [
"Mexico",
"India",
"China",
"Cuba",
"Dominican Rep",
"Philippines"
]
},
"y": {
"field": "year",
"type": "nominal",
"sort": [
"2014",
"2015",
"2016",
"2017",
"2018",
"2019",
"2020",
"2021",
"2022",
"2023"
]
},
"color": {
"field": "cards",
"type": "quantitative",
"scale": {
"scheme": "blue"
},
"format": ",.0f"
}
}
},
{
"mark": {
"type": "text",
"fill": "#ffffff",
"fontSize": 12
},
"transform": [
{
"filter": {
"field": "cards",
"gte": 150
}
}
],
"data": [
{
"country": "Mexico",
"year": "2014",
"cards": 134
},
{
"country": "India",
"year": "2014",
"cards": 78
},
{
"country": "China",
"year": "2014",
"cards": 76
},
{
"country": "Cuba",
"year": "2014",
"cards": 47
},
{
"country": "Dominican Rep",
"year": "2014",
"cards": 45
},
{
"country": "Philippines",
"year": "2014",
"cards": 50
},
{
"country": "Mexico",
"year": "2015",
"cards": 159
},
{
"country": "India",
"year": "2015",
"cards": 64
},
{
"country": "China",
"year": "2015",
"cards": 75
},
{
"country": "Cuba",
"year": "2015",
"cards": 54
},
{
"country": "Dominican Rep",
"year": "2015",
"cards": 51
},
{
"country": "Philippines",
"year": "2015",
"cards": 56
},
{
"country": "Mexico",
"year": "2016",
"cards": 175
},
{
"country": "India",
"year": "2016",
"cards": 65
},
{
"country": "China",
"year": "2016",
"cards": 82
},
{
"country": "Cuba",
"year": "2016",
"cards": 67
},
{
"country": "Dominican Rep",
"year": "2016",
"cards": 61
},
{
"country": "Philippines",
"year": "2016",
"cards": 53
},
{
"country": "Mexico",
"year": "2017",
"cards": 171
},
{
"country": "India",
"year": "2017",
"cards": 60
},
{
"country": "China",
"year": "2017",
"cards": 72
},
{
"country": "Cuba",
"year": "2017",
"cards": 65
},
{
"country": "Dominican Rep",
"year": "2017",
"cards": 59
},
{
"country": "Philippines",
"year": "2017",
"cards": 49
},
{
"country": "Mexico",
"year": "2018",
"cards": 162
},
{
"country": "India",
"year": "2018",
"cards": 60
},
{
"country": "China",
"year": "2018",
"cards": 65
},
{
"country": "Cuba",
"year": "2018",
"cards": 76
},
{
"country": "Dominican Rep",
"year": "2018",
"cards": 57
},
{
"country": "Philippines",
"year": "2018",
"cards": 47
},
{
"country": "Mexico",
"year": "2019",
"cards": 156
},
{
"country": "India",
"year": "2019",
"cards": 55
},
{
"country": "China",
"year": "2019",
"cards": 62
},
{
"country": "Cuba",
"year": "2019",
"cards": 42
},
{
"country": "Dominican Rep",
"year": "2019",
"cards": 50
},
{
"country": "Philippines",
"year": "2019",
"cards": 46
},
{
"country": "Mexico",
"year": "2020",
"cards": 100
},
{
"country": "India",
"year": "2020",
"cards": 46
},
{
"country": "China",
"year": "2020",
"cards": 41
},
{
"country": "Cuba",
"year": "2020",
"cards": 16
},
{
"country": "Dominican Rep",
"year": "2020",
"cards": 30
},
{
"country": "Philippines",
"year": "2020",
"cards": 25
},
{
"country": "Mexico",
"year": "2021",
"cards": 107
},
{
"country": "India",
"year": "2021",
"cards": 93
},
{
"country": "China",
"year": "2021",
"cards": 50
},
{
"country": "Cuba",
"year": "2021",
"cards": 23
},
{
"country": "Dominican Rep",
"year": "2021",
"cards": 25
},
{
"country": "Philippines",
"year": "2021",
"cards": 28
},
{
"country": "Mexico",
"year": "2022",
"cards": 139
},
{
"country": "India",
"year": "2022",
"cards": 127
},
{
"country": "China",
"year": "2022",
"cards": 68
},
{
"country": "Cuba",
"year": "2022",
"cards": 37
},
{
"country": "Dominican Rep",
"year": "2022",
"cards": 40
},
{
"country": "Philippines",
"year": "2022",
"cards": 36
},
{
"country": "Mexico",
"year": "2023",
"cards": 181
},
{
"country": "India",
"year": "2023",
"cards": 78
},
{
"country": "China",
"year": "2023",
"cards": 59
},
{
"country": "Cuba",
"year": "2023",
"cards": 82
},
{
"country": "Dominican Rep",
"year": "2023",
"cards": 69
},
{
"country": "Philippines",
"year": "2023",
"cards": 49
}
],
"encoding": {
"x": {
"field": "country",
"type": "nominal",
"sort": [
"Mexico",
"India",
"China",
"Cuba",
"Dominican Rep",
"Philippines"
]
},
"y": {
"field": "year",
"type": "nominal",
"sort": [
"2014",
"2015",
"2016",
"2017",
"2018",
"2019",
"2020",
"2021",
"2022",
"2023"
]
},
"text": {
"field": "cards",
"type": "quantitative"
}
}
},
{
"mark": {
"type": "text",
"fill": "#0f172a",
"fontSize": 12
},
"transform": [
{
"filter": {
"field": "cards",
"lt": 150
}
}
],
"data": [
{
"country": "Mexico",
"year": "2014",
"cards": 134
},
{
"country": "India",
"year": "2014",
"cards": 78
},
{
"country": "China",
"year": "2014",
"cards": 76
},
{
"country": "Cuba",
"year": "2014",
"cards": 47
},
{
"country": "Dominican Rep",
"year": "2014",
"cards": 45
},
{
"country": "Philippines",
"year": "2014",
"cards": 50
},
{
"country": "Mexico",
"year": "2015",
"cards": 159
},
{
"country": "India",
"year": "2015",
"cards": 64
},
{
"country": "China",
"year": "2015",
"cards": 75
},
{
"country": "Cuba",
"year": "2015",
"cards": 54
},
{
"country": "Dominican Rep",
"year": "2015",
"cards": 51
},
{
"country": "Philippines",
"year": "2015",
"cards": 56
},
{
"country": "Mexico",
"year": "2016",
"cards": 175
},
{
"country": "India",
"year": "2016",
"cards": 65
},
{
"country": "China",
"year": "2016",
"cards": 82
},
{
"country": "Cuba",
"year": "2016",
"cards": 67
},
{
"country": "Dominican Rep",
"year": "2016",
"cards": 61
},
{
"country": "Philippines",
"year": "2016",
"cards": 53
},
{
"country": "Mexico",
"year": "2017",
"cards": 171
},
{
"country": "India",
"year": "2017",
"cards": 60
},
{
"country": "China",
"year": "2017",
"cards": 72
},
{
"country": "Cuba",
"year": "2017",
"cards": 65
},
{
"country": "Dominican Rep",
"year": "2017",
"cards": 59
},
{
"country": "Philippines",
"year": "2017",
"cards": 49
},
{
"country": "Mexico",
"year": "2018",
"cards": 162
},
{
"country": "India",
"year": "2018",
"cards": 60
},
{
"country": "China",
"year": "2018",
"cards": 65
},
{
"country": "Cuba",
"year": "2018",
"cards": 76
},
{
"country": "Dominican Rep",
"year": "2018",
"cards": 57
},
{
"country": "Philippines",
"year": "2018",
"cards": 47
},
{
"country": "Mexico",
"year": "2019",
"cards": 156
},
{
"country": "India",
"year": "2019",
"cards": 55
},
{
"country": "China",
"year": "2019",
"cards": 62
},
{
"country": "Cuba",
"year": "2019",
"cards": 42
},
{
"country": "Dominican Rep",
"year": "2019",
"cards": 50
},
{
"country": "Philippines",
"year": "2019",
"cards": 46
},
{
"country": "Mexico",
"year": "2020",
"cards": 100
},
{
"country": "India",
"year": "2020",
"cards": 46
},
{
"country": "China",
"year": "2020",
"cards": 41
},
{
"country": "Cuba",
"year": "2020",
"cards": 16
},
{
"country": "Dominican Rep",
"year": "2020",
"cards": 30
},
{
"country": "Philippines",
"year": "2020",
"cards": 25
},
{
"country": "Mexico",
"year": "2021",
"cards": 107
},
{
"country": "India",
"year": "2021",
"cards": 93
},
{
"country": "China",
"year": "2021",
"cards": 50
},
{
"country": "Cuba",
"year": "2021",
"cards": 23
},
{
"country": "Dominican Rep",
"year": "2021",
"cards": 25
},
{
"country": "Philippines",
"year": "2021",
"cards": 28
},
{
"country": "Mexico",
"year": "2022",
"cards": 139
},
{
"country": "India",
"year": "2022",
"cards": 127
},
{
"country": "China",
"year": "2022",
"cards": 68
},
{
"country": "Cuba",
"year": "2022",
"cards": 37
},
{
"country": "Dominican Rep",
"year": "2022",
"cards": 40
},
{
"country": "Philippines",
"year": "2022",
"cards": 36
},
{
"country": "Mexico",
"year": "2023",
"cards": 181
},
{
"country": "India",
"year": "2023",
"cards": 78
},
{
"country": "China",
"year": "2023",
"cards": 59
},
{
"country": "Cuba",
"year": "2023",
"cards": 82
},
{
"country": "Dominican Rep",
"year": "2023",
"cards": 69
},
{
"country": "Philippines",
"year": "2023",
"cards": 49
}
],
"encoding": {
"x": {
"field": "country",
"type": "nominal",
"sort": [
"Mexico",
"India",
"China",
"Cuba",
"Dominican Rep",
"Philippines"
]
},
"y": {
"field": "year",
"type": "nominal",
"sort": [
"2014",
"2015",
"2016",
"2017",
"2018",
"2019",
"2020",
"2021",
"2022",
"2023"
]
},
"text": {
"field": "cards",
"type": "quantitative"
}
}
}
],
"chrome": {
"title": "Green cards fell 31% in fiscal 2020, with drops for all six countries",
"subtitle": "New green-card holders by country of birth and fiscal year, in thousands"
}
}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": "rect",
"data": [
{
"country": "Mexico",
"year": "2014",
"cards": 134
},
{
"country": "India",
"year": "2014",
"cards": 78
},
{
"country": "China",
"year": "2014",
"cards": 76
},
{
"country": "Cuba",
"year": "2014",
"cards": 47
},
{
"country": "Dominican Rep",
"year": "2014",
"cards": 45
},
{
"country": "Philippines",
"year": "2014",
"cards": 50
},
{
"country": "Mexico",
"year": "2015",
"cards": 159
},
{
"country": "India",
"year": "2015",
"cards": 64
},
{
"country": "China",
"year": "2015",
"cards": 75
},
{
"country": "Cuba",
"year": "2015",
"cards": 54
},
{
"country": "Dominican Rep",
"year": "2015",
"cards": 51
},
{
"country": "Philippines",
"year": "2015",
"cards": 56
},
{
"country": "Mexico",
"year": "2016",
"cards": 175
},
{
"country": "India",
"year": "2016",
"cards": 65
},
{
"country": "China",
"year": "2016",
"cards": 82
},
{
"country": "Cuba",
"year": "2016",
"cards": 67
},
{
"country": "Dominican Rep",
"year": "2016",
"cards": 61
},
{
"country": "Philippines",
"year": "2016",
"cards": 53
},
{
"country": "Mexico",
"year": "2017",
"cards": 171
},
{
"country": "India",
"year": "2017",
"cards": 60
},
{
"country": "China",
"year": "2017",
"cards": 72
},
{
"country": "Cuba",
"year": "2017",
"cards": 65
},
{
"country": "Dominican Rep",
"year": "2017",
"cards": 59
},
{
"country": "Philippines",
"year": "2017",
"cards": 49
},
{
"country": "Mexico",
"year": "2018",
"cards": 162
},
{
"country": "India",
"year": "2018",
"cards": 60
},
{
"country": "China",
"year": "2018",
"cards": 65
},
{
"country": "Cuba",
"year": "2018",
"cards": 76
},
{
"country": "Dominican Rep",
"year": "2018",
"cards": 57
},
{
"country": "Philippines",
"year": "2018",
"cards": 47
},
{
"country": "Mexico",
"year": "2019",
"cards": 156
},
{
"country": "India",
"year": "2019",
"cards": 55
},
{
"country": "China",
"year": "2019",
"cards": 62
},
{
"country": "Cuba",
"year": "2019",
"cards": 42
},
{
"country": "Dominican Rep",
"year": "2019",
"cards": 50
},
{
"country": "Philippines",
"year": "2019",
"cards": 46
},
{
"country": "Mexico",
"year": "2020",
"cards": 100
},
{
"country": "India",
"year": "2020",
"cards": 46
},
{
"country": "China",
"year": "2020",
"cards": 41
},
{
"country": "Cuba",
"year": "2020",
"cards": 16
},
{
"country": "Dominican Rep",
"year": "2020",
"cards": 30
},
{
"country": "Philippines",
"year": "2020",
"cards": 25
},
{
"country": "Mexico",
"year": "2021",
"cards": 107
},
{
"country": "India",
"year": "2021",
"cards": 93
},
{
"country": "China",
"year": "2021",
"cards": 50
},
{
"country": "Cuba",
"year": "2021",
"cards": 23
},
{
"country": "Dominican Rep",
"year": "2021",
"cards": 25
},
{
"country": "Philippines",
"year": "2021",
"cards": 28
},
{
"country": "Mexico",
"year": "2022",
"cards": 139
},
{
"country": "India",
"year": "2022",
"cards": 127
},
{
"country": "China",
"year": "2022",
"cards": 68
},
{
"country": "Cuba",
"year": "2022",
"cards": 37
},
{
"country": "Dominican Rep",
"year": "2022",
"cards": 40
},
{
"country": "Philippines",
"year": "2022",
"cards": 36
},
{
"country": "Mexico",
"year": "2023",
"cards": 181
},
{
"country": "India",
"year": "2023",
"cards": 78
},
{
"country": "China",
"year": "2023",
"cards": 59
},
{
"country": "Cuba",
"year": "2023",
"cards": 82
},
{
"country": "Dominican Rep",
"year": "2023",
"cards": 69
},
{
"country": "Philippines",
"year": "2023",
"cards": 49
}
],
"encoding": {
"x": {
"field": "country",
"type": "nominal",
"sort": [
"Mexico",
"India",
"China",
"Cuba",
"Dominican Rep",
"Philippines"
]
},
"y": {
"field": "year",
"type": "nominal",
"sort": [
"2014",
"2015",
"2016",
"2017",
"2018",
"2019",
"2020",
"2021",
"2022",
"2023"
]
},
"color": {
"field": "cards",
"type": "quantitative",
"scale": {
"scheme": "blue"
},
"format": ",.0f"
}
}
},
{
"mark": {
"type": "text",
"fill": "#ffffff",
"fontSize": 12
},
"transform": [
{
"filter": {
"field": "cards",
"gte": 150
}
}
],
"data": [
{
"country": "Mexico",
"year": "2014",
"cards": 134
},
{
"country": "India",
"year": "2014",
"cards": 78
},
{
"country": "China",
"year": "2014",
"cards": 76
},
{
"country": "Cuba",
"year": "2014",
"cards": 47
},
{
"country": "Dominican Rep",
"year": "2014",
"cards": 45
},
{
"country": "Philippines",
"year": "2014",
"cards": 50
},
{
"country": "Mexico",
"year": "2015",
"cards": 159
},
{
"country": "India",
"year": "2015",
"cards": 64
},
{
"country": "China",
"year": "2015",
"cards": 75
},
{
"country": "Cuba",
"year": "2015",
"cards": 54
},
{
"country": "Dominican Rep",
"year": "2015",
"cards": 51
},
{
"country": "Philippines",
"year": "2015",
"cards": 56
},
{
"country": "Mexico",
"year": "2016",
"cards": 175
},
{
"country": "India",
"year": "2016",
"cards": 65
},
{
"country": "China",
"year": "2016",
"cards": 82
},
{
"country": "Cuba",
"year": "2016",
"cards": 67
},
{
"country": "Dominican Rep",
"year": "2016",
"cards": 61
},
{
"country": "Philippines",
"year": "2016",
"cards": 53
},
{
"country": "Mexico",
"year": "2017",
"cards": 171
},
{
"country": "India",
"year": "2017",
"cards": 60
},
{
"country": "China",
"year": "2017",
"cards": 72
},
{
"country": "Cuba",
"year": "2017",
"cards": 65
},
{
"country": "Dominican Rep",
"year": "2017",
"cards": 59
},
{
"country": "Philippines",
"year": "2017",
"cards": 49
},
{
"country": "Mexico",
"year": "2018",
"cards": 162
},
{
"country": "India",
"year": "2018",
"cards": 60
},
{
"country": "China",
"year": "2018",
"cards": 65
},
{
"country": "Cuba",
"year": "2018",
"cards": 76
},
{
"country": "Dominican Rep",
"year": "2018",
"cards": 57
},
{
"country": "Philippines",
"year": "2018",
"cards": 47
},
{
"country": "Mexico",
"year": "2019",
"cards": 156
},
{
"country": "India",
"year": "2019",
"cards": 55
},
{
"country": "China",
"year": "2019",
"cards": 62
},
{
"country": "Cuba",
"year": "2019",
"cards": 42
},
{
"country": "Dominican Rep",
"year": "2019",
"cards": 50
},
{
"country": "Philippines",
"year": "2019",
"cards": 46
},
{
"country": "Mexico",
"year": "2020",
"cards": 100
},
{
"country": "India",
"year": "2020",
"cards": 46
},
{
"country": "China",
"year": "2020",
"cards": 41
},
{
"country": "Cuba",
"year": "2020",
"cards": 16
},
{
"country": "Dominican Rep",
"year": "2020",
"cards": 30
},
{
"country": "Philippines",
"year": "2020",
"cards": 25
},
{
"country": "Mexico",
"year": "2021",
"cards": 107
},
{
"country": "India",
"year": "2021",
"cards": 93
},
{
"country": "China",
"year": "2021",
"cards": 50
},
{
"country": "Cuba",
"year": "2021",
"cards": 23
},
{
"country": "Dominican Rep",
"year": "2021",
"cards": 25
},
{
"country": "Philippines",
"year": "2021",
"cards": 28
},
{
"country": "Mexico",
"year": "2022",
"cards": 139
},
{
"country": "India",
"year": "2022",
"cards": 127
},
{
"country": "China",
"year": "2022",
"cards": 68
},
{
"country": "Cuba",
"year": "2022",
"cards": 37
},
{
"country": "Dominican Rep",
"year": "2022",
"cards": 40
},
{
"country": "Philippines",
"year": "2022",
"cards": 36
},
{
"country": "Mexico",
"year": "2023",
"cards": 181
},
{
"country": "India",
"year": "2023",
"cards": 78
},
{
"country": "China",
"year": "2023",
"cards": 59
},
{
"country": "Cuba",
"year": "2023",
"cards": 82
},
{
"country": "Dominican Rep",
"year": "2023",
"cards": 69
},
{
"country": "Philippines",
"year": "2023",
"cards": 49
}
],
"encoding": {
"x": {
"field": "country",
"type": "nominal",
"sort": [
"Mexico",
"India",
"China",
"Cuba",
"Dominican Rep",
"Philippines"
]
},
"y": {
"field": "year",
"type": "nominal",
"sort": [
"2014",
"2015",
"2016",
"2017",
"2018",
"2019",
"2020",
"2021",
"2022",
"2023"
]
},
"text": {
"field": "cards",
"type": "quantitative"
}
}
},
{
"mark": {
"type": "text",
"fill": "#0f172a",
"fontSize": 12
},
"transform": [
{
"filter": {
"field": "cards",
"lt": 150
}
}
],
"data": [
{
"country": "Mexico",
"year": "2014",
"cards": 134
},
{
"country": "India",
"year": "2014",
"cards": 78
},
{
"country": "China",
"year": "2014",
"cards": 76
},
{
"country": "Cuba",
"year": "2014",
"cards": 47
},
{
"country": "Dominican Rep",
"year": "2014",
"cards": 45
},
{
"country": "Philippines",
"year": "2014",
"cards": 50
},
{
"country": "Mexico",
"year": "2015",
"cards": 159
},
{
"country": "India",
"year": "2015",
"cards": 64
},
{
"country": "China",
"year": "2015",
"cards": 75
},
{
"country": "Cuba",
"year": "2015",
"cards": 54
},
{
"country": "Dominican Rep",
"year": "2015",
"cards": 51
},
{
"country": "Philippines",
"year": "2015",
"cards": 56
},
{
"country": "Mexico",
"year": "2016",
"cards": 175
},
{
"country": "India",
"year": "2016",
"cards": 65
},
{
"country": "China",
"year": "2016",
"cards": 82
},
{
"country": "Cuba",
"year": "2016",
"cards": 67
},
{
"country": "Dominican Rep",
"year": "2016",
"cards": 61
},
{
"country": "Philippines",
"year": "2016",
"cards": 53
},
{
"country": "Mexico",
"year": "2017",
"cards": 171
},
{
"country": "India",
"year": "2017",
"cards": 60
},
{
"country": "China",
"year": "2017",
"cards": 72
},
{
"country": "Cuba",
"year": "2017",
"cards": 65
},
{
"country": "Dominican Rep",
"year": "2017",
"cards": 59
},
{
"country": "Philippines",
"year": "2017",
"cards": 49
},
{
"country": "Mexico",
"year": "2018",
"cards": 162
},
{
"country": "India",
"year": "2018",
"cards": 60
},
{
"country": "China",
"year": "2018",
"cards": 65
},
{
"country": "Cuba",
"year": "2018",
"cards": 76
},
{
"country": "Dominican Rep",
"year": "2018",
"cards": 57
},
{
"country": "Philippines",
"year": "2018",
"cards": 47
},
{
"country": "Mexico",
"year": "2019",
"cards": 156
},
{
"country": "India",
"year": "2019",
"cards": 55
},
{
"country": "China",
"year": "2019",
"cards": 62
},
{
"country": "Cuba",
"year": "2019",
"cards": 42
},
{
"country": "Dominican Rep",
"year": "2019",
"cards": 50
},
{
"country": "Philippines",
"year": "2019",
"cards": 46
},
{
"country": "Mexico",
"year": "2020",
"cards": 100
},
{
"country": "India",
"year": "2020",
"cards": 46
},
{
"country": "China",
"year": "2020",
"cards": 41
},
{
"country": "Cuba",
"year": "2020",
"cards": 16
},
{
"country": "Dominican Rep",
"year": "2020",
"cards": 30
},
{
"country": "Philippines",
"year": "2020",
"cards": 25
},
{
"country": "Mexico",
"year": "2021",
"cards": 107
},
{
"country": "India",
"year": "2021",
"cards": 93
},
{
"country": "China",
"year": "2021",
"cards": 50
},
{
"country": "Cuba",
"year": "2021",
"cards": 23
},
{
"country": "Dominican Rep",
"year": "2021",
"cards": 25
},
{
"country": "Philippines",
"year": "2021",
"cards": 28
},
{
"country": "Mexico",
"year": "2022",
"cards": 139
},
{
"country": "India",
"year": "2022",
"cards": 127
},
{
"country": "China",
"year": "2022",
"cards": 68
},
{
"country": "Cuba",
"year": "2022",
"cards": 37
},
{
"country": "Dominican Rep",
"year": "2022",
"cards": 40
},
{
"country": "Philippines",
"year": "2022",
"cards": 36
},
{
"country": "Mexico",
"year": "2023",
"cards": 181
},
{
"country": "India",
"year": "2023",
"cards": 78
},
{
"country": "China",
"year": "2023",
"cards": 59
},
{
"country": "Cuba",
"year": "2023",
"cards": 82
},
{
"country": "Dominican Rep",
"year": "2023",
"cards": 69
},
{
"country": "Philippines",
"year": "2023",
"cards": 49
}
],
"encoding": {
"x": {
"field": "country",
"type": "nominal",
"sort": [
"Mexico",
"India",
"China",
"Cuba",
"Dominican Rep",
"Philippines"
]
},
"y": {
"field": "year",
"type": "nominal",
"sort": [
"2014",
"2015",
"2016",
"2017",
"2018",
"2019",
"2020",
"2021",
"2022",
"2023"
]
},
"text": {
"field": "cards",
"type": "quantitative"
}
}
}
],
"chrome": {
"title": "Green cards fell 31% in fiscal 2020, with drops for all six countries",
"subtitle": "New green-card holders by country of birth and fiscal year, in thousands"
}
};
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": "rect",
"data": [
{
"country": "Mexico",
"year": "2014",
"cards": 134
},
{
"country": "India",
"year": "2014",
"cards": 78
},
{
"country": "China",
"year": "2014",
"cards": 76
},
{
"country": "Cuba",
"year": "2014",
"cards": 47
},
{
"country": "Dominican Rep",
"year": "2014",
"cards": 45
},
{
"country": "Philippines",
"year": "2014",
"cards": 50
},
{
"country": "Mexico",
"year": "2015",
"cards": 159
},
{
"country": "India",
"year": "2015",
"cards": 64
},
{
"country": "China",
"year": "2015",
"cards": 75
},
{
"country": "Cuba",
"year": "2015",
"cards": 54
},
{
"country": "Dominican Rep",
"year": "2015",
"cards": 51
},
{
"country": "Philippines",
"year": "2015",
"cards": 56
},
{
"country": "Mexico",
"year": "2016",
"cards": 175
},
{
"country": "India",
"year": "2016",
"cards": 65
},
{
"country": "China",
"year": "2016",
"cards": 82
},
{
"country": "Cuba",
"year": "2016",
"cards": 67
},
{
"country": "Dominican Rep",
"year": "2016",
"cards": 61
},
{
"country": "Philippines",
"year": "2016",
"cards": 53
},
{
"country": "Mexico",
"year": "2017",
"cards": 171
},
{
"country": "India",
"year": "2017",
"cards": 60
},
{
"country": "China",
"year": "2017",
"cards": 72
},
{
"country": "Cuba",
"year": "2017",
"cards": 65
},
{
"country": "Dominican Rep",
"year": "2017",
"cards": 59
},
{
"country": "Philippines",
"year": "2017",
"cards": 49
},
{
"country": "Mexico",
"year": "2018",
"cards": 162
},
{
"country": "India",
"year": "2018",
"cards": 60
},
{
"country": "China",
"year": "2018",
"cards": 65
},
{
"country": "Cuba",
"year": "2018",
"cards": 76
},
{
"country": "Dominican Rep",
"year": "2018",
"cards": 57
},
{
"country": "Philippines",
"year": "2018",
"cards": 47
},
{
"country": "Mexico",
"year": "2019",
"cards": 156
},
{
"country": "India",
"year": "2019",
"cards": 55
},
{
"country": "China",
"year": "2019",
"cards": 62
},
{
"country": "Cuba",
"year": "2019",
"cards": 42
},
{
"country": "Dominican Rep",
"year": "2019",
"cards": 50
},
{
"country": "Philippines",
"year": "2019",
"cards": 46
},
{
"country": "Mexico",
"year": "2020",
"cards": 100
},
{
"country": "India",
"year": "2020",
"cards": 46
},
{
"country": "China",
"year": "2020",
"cards": 41
},
{
"country": "Cuba",
"year": "2020",
"cards": 16
},
{
"country": "Dominican Rep",
"year": "2020",
"cards": 30
},
{
"country": "Philippines",
"year": "2020",
"cards": 25
},
{
"country": "Mexico",
"year": "2021",
"cards": 107
},
{
"country": "India",
"year": "2021",
"cards": 93
},
{
"country": "China",
"year": "2021",
"cards": 50
},
{
"country": "Cuba",
"year": "2021",
"cards": 23
},
{
"country": "Dominican Rep",
"year": "2021",
"cards": 25
},
{
"country": "Philippines",
"year": "2021",
"cards": 28
},
{
"country": "Mexico",
"year": "2022",
"cards": 139
},
{
"country": "India",
"year": "2022",
"cards": 127
},
{
"country": "China",
"year": "2022",
"cards": 68
},
{
"country": "Cuba",
"year": "2022",
"cards": 37
},
{
"country": "Dominican Rep",
"year": "2022",
"cards": 40
},
{
"country": "Philippines",
"year": "2022",
"cards": 36
},
{
"country": "Mexico",
"year": "2023",
"cards": 181
},
{
"country": "India",
"year": "2023",
"cards": 78
},
{
"country": "China",
"year": "2023",
"cards": 59
},
{
"country": "Cuba",
"year": "2023",
"cards": 82
},
{
"country": "Dominican Rep",
"year": "2023",
"cards": 69
},
{
"country": "Philippines",
"year": "2023",
"cards": 49
}
],
"encoding": {
"x": {
"field": "country",
"type": "nominal",
"sort": [
"Mexico",
"India",
"China",
"Cuba",
"Dominican Rep",
"Philippines"
]
},
"y": {
"field": "year",
"type": "nominal",
"sort": [
"2014",
"2015",
"2016",
"2017",
"2018",
"2019",
"2020",
"2021",
"2022",
"2023"
]
},
"color": {
"field": "cards",
"type": "quantitative",
"scale": {
"scheme": "blue"
},
"format": ",.0f"
}
}
},
{
"mark": {
"type": "text",
"fill": "#ffffff",
"fontSize": 12
},
"transform": [
{
"filter": {
"field": "cards",
"gte": 150
}
}
],
"data": [
{
"country": "Mexico",
"year": "2014",
"cards": 134
},
{
"country": "India",
"year": "2014",
"cards": 78
},
{
"country": "China",
"year": "2014",
"cards": 76
},
{
"country": "Cuba",
"year": "2014",
"cards": 47
},
{
"country": "Dominican Rep",
"year": "2014",
"cards": 45
},
{
"country": "Philippines",
"year": "2014",
"cards": 50
},
{
"country": "Mexico",
"year": "2015",
"cards": 159
},
{
"country": "India",
"year": "2015",
"cards": 64
},
{
"country": "China",
"year": "2015",
"cards": 75
},
{
"country": "Cuba",
"year": "2015",
"cards": 54
},
{
"country": "Dominican Rep",
"year": "2015",
"cards": 51
},
{
"country": "Philippines",
"year": "2015",
"cards": 56
},
{
"country": "Mexico",
"year": "2016",
"cards": 175
},
{
"country": "India",
"year": "2016",
"cards": 65
},
{
"country": "China",
"year": "2016",
"cards": 82
},
{
"country": "Cuba",
"year": "2016",
"cards": 67
},
{
"country": "Dominican Rep",
"year": "2016",
"cards": 61
},
{
"country": "Philippines",
"year": "2016",
"cards": 53
},
{
"country": "Mexico",
"year": "2017",
"cards": 171
},
{
"country": "India",
"year": "2017",
"cards": 60
},
{
"country": "China",
"year": "2017",
"cards": 72
},
{
"country": "Cuba",
"year": "2017",
"cards": 65
},
{
"country": "Dominican Rep",
"year": "2017",
"cards": 59
},
{
"country": "Philippines",
"year": "2017",
"cards": 49
},
{
"country": "Mexico",
"year": "2018",
"cards": 162
},
{
"country": "India",
"year": "2018",
"cards": 60
},
{
"country": "China",
"year": "2018",
"cards": 65
},
{
"country": "Cuba",
"year": "2018",
"cards": 76
},
{
"country": "Dominican Rep",
"year": "2018",
"cards": 57
},
{
"country": "Philippines",
"year": "2018",
"cards": 47
},
{
"country": "Mexico",
"year": "2019",
"cards": 156
},
{
"country": "India",
"year": "2019",
"cards": 55
},
{
"country": "China",
"year": "2019",
"cards": 62
},
{
"country": "Cuba",
"year": "2019",
"cards": 42
},
{
"country": "Dominican Rep",
"year": "2019",
"cards": 50
},
{
"country": "Philippines",
"year": "2019",
"cards": 46
},
{
"country": "Mexico",
"year": "2020",
"cards": 100
},
{
"country": "India",
"year": "2020",
"cards": 46
},
{
"country": "China",
"year": "2020",
"cards": 41
},
{
"country": "Cuba",
"year": "2020",
"cards": 16
},
{
"country": "Dominican Rep",
"year": "2020",
"cards": 30
},
{
"country": "Philippines",
"year": "2020",
"cards": 25
},
{
"country": "Mexico",
"year": "2021",
"cards": 107
},
{
"country": "India",
"year": "2021",
"cards": 93
},
{
"country": "China",
"year": "2021",
"cards": 50
},
{
"country": "Cuba",
"year": "2021",
"cards": 23
},
{
"country": "Dominican Rep",
"year": "2021",
"cards": 25
},
{
"country": "Philippines",
"year": "2021",
"cards": 28
},
{
"country": "Mexico",
"year": "2022",
"cards": 139
},
{
"country": "India",
"year": "2022",
"cards": 127
},
{
"country": "China",
"year": "2022",
"cards": 68
},
{
"country": "Cuba",
"year": "2022",
"cards": 37
},
{
"country": "Dominican Rep",
"year": "2022",
"cards": 40
},
{
"country": "Philippines",
"year": "2022",
"cards": 36
},
{
"country": "Mexico",
"year": "2023",
"cards": 181
},
{
"country": "India",
"year": "2023",
"cards": 78
},
{
"country": "China",
"year": "2023",
"cards": 59
},
{
"country": "Cuba",
"year": "2023",
"cards": 82
},
{
"country": "Dominican Rep",
"year": "2023",
"cards": 69
},
{
"country": "Philippines",
"year": "2023",
"cards": 49
}
],
"encoding": {
"x": {
"field": "country",
"type": "nominal",
"sort": [
"Mexico",
"India",
"China",
"Cuba",
"Dominican Rep",
"Philippines"
]
},
"y": {
"field": "year",
"type": "nominal",
"sort": [
"2014",
"2015",
"2016",
"2017",
"2018",
"2019",
"2020",
"2021",
"2022",
"2023"
]
},
"text": {
"field": "cards",
"type": "quantitative"
}
}
},
{
"mark": {
"type": "text",
"fill": "#0f172a",
"fontSize": 12
},
"transform": [
{
"filter": {
"field": "cards",
"lt": 150
}
}
],
"data": [
{
"country": "Mexico",
"year": "2014",
"cards": 134
},
{
"country": "India",
"year": "2014",
"cards": 78
},
{
"country": "China",
"year": "2014",
"cards": 76
},
{
"country": "Cuba",
"year": "2014",
"cards": 47
},
{
"country": "Dominican Rep",
"year": "2014",
"cards": 45
},
{
"country": "Philippines",
"year": "2014",
"cards": 50
},
{
"country": "Mexico",
"year": "2015",
"cards": 159
},
{
"country": "India",
"year": "2015",
"cards": 64
},
{
"country": "China",
"year": "2015",
"cards": 75
},
{
"country": "Cuba",
"year": "2015",
"cards": 54
},
{
"country": "Dominican Rep",
"year": "2015",
"cards": 51
},
{
"country": "Philippines",
"year": "2015",
"cards": 56
},
{
"country": "Mexico",
"year": "2016",
"cards": 175
},
{
"country": "India",
"year": "2016",
"cards": 65
},
{
"country": "China",
"year": "2016",
"cards": 82
},
{
"country": "Cuba",
"year": "2016",
"cards": 67
},
{
"country": "Dominican Rep",
"year": "2016",
"cards": 61
},
{
"country": "Philippines",
"year": "2016",
"cards": 53
},
{
"country": "Mexico",
"year": "2017",
"cards": 171
},
{
"country": "India",
"year": "2017",
"cards": 60
},
{
"country": "China",
"year": "2017",
"cards": 72
},
{
"country": "Cuba",
"year": "2017",
"cards": 65
},
{
"country": "Dominican Rep",
"year": "2017",
"cards": 59
},
{
"country": "Philippines",
"year": "2017",
"cards": 49
},
{
"country": "Mexico",
"year": "2018",
"cards": 162
},
{
"country": "India",
"year": "2018",
"cards": 60
},
{
"country": "China",
"year": "2018",
"cards": 65
},
{
"country": "Cuba",
"year": "2018",
"cards": 76
},
{
"country": "Dominican Rep",
"year": "2018",
"cards": 57
},
{
"country": "Philippines",
"year": "2018",
"cards": 47
},
{
"country": "Mexico",
"year": "2019",
"cards": 156
},
{
"country": "India",
"year": "2019",
"cards": 55
},
{
"country": "China",
"year": "2019",
"cards": 62
},
{
"country": "Cuba",
"year": "2019",
"cards": 42
},
{
"country": "Dominican Rep",
"year": "2019",
"cards": 50
},
{
"country": "Philippines",
"year": "2019",
"cards": 46
},
{
"country": "Mexico",
"year": "2020",
"cards": 100
},
{
"country": "India",
"year": "2020",
"cards": 46
},
{
"country": "China",
"year": "2020",
"cards": 41
},
{
"country": "Cuba",
"year": "2020",
"cards": 16
},
{
"country": "Dominican Rep",
"year": "2020",
"cards": 30
},
{
"country": "Philippines",
"year": "2020",
"cards": 25
},
{
"country": "Mexico",
"year": "2021",
"cards": 107
},
{
"country": "India",
"year": "2021",
"cards": 93
},
{
"country": "China",
"year": "2021",
"cards": 50
},
{
"country": "Cuba",
"year": "2021",
"cards": 23
},
{
"country": "Dominican Rep",
"year": "2021",
"cards": 25
},
{
"country": "Philippines",
"year": "2021",
"cards": 28
},
{
"country": "Mexico",
"year": "2022",
"cards": 139
},
{
"country": "India",
"year": "2022",
"cards": 127
},
{
"country": "China",
"year": "2022",
"cards": 68
},
{
"country": "Cuba",
"year": "2022",
"cards": 37
},
{
"country": "Dominican Rep",
"year": "2022",
"cards": 40
},
{
"country": "Philippines",
"year": "2022",
"cards": 36
},
{
"country": "Mexico",
"year": "2023",
"cards": 181
},
{
"country": "India",
"year": "2023",
"cards": 78
},
{
"country": "China",
"year": "2023",
"cards": 59
},
{
"country": "Cuba",
"year": "2023",
"cards": 82
},
{
"country": "Dominican Rep",
"year": "2023",
"cards": 69
},
{
"country": "Philippines",
"year": "2023",
"cards": 49
}
],
"encoding": {
"x": {
"field": "country",
"type": "nominal",
"sort": [
"Mexico",
"India",
"China",
"Cuba",
"Dominican Rep",
"Philippines"
]
},
"y": {
"field": "year",
"type": "nominal",
"sort": [
"2014",
"2015",
"2016",
"2017",
"2018",
"2019",
"2020",
"2021",
"2022",
"2023"
]
},
"text": {
"field": "cards",
"type": "quantitative"
}
}
}
],
"chrome": {
"title": "Green cards fell 31% in fiscal 2020, with drops for all six countries",
"subtitle": "New green-card holders by country of birth and fiscal year, in thousands"
}
};
</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": "rect",
"data": [
{
"country": "Mexico",
"year": "2014",
"cards": 134
},
{
"country": "India",
"year": "2014",
"cards": 78
},
{
"country": "China",
"year": "2014",
"cards": 76
},
{
"country": "Cuba",
"year": "2014",
"cards": 47
},
{
"country": "Dominican Rep",
"year": "2014",
"cards": 45
},
{
"country": "Philippines",
"year": "2014",
"cards": 50
},
{
"country": "Mexico",
"year": "2015",
"cards": 159
},
{
"country": "India",
"year": "2015",
"cards": 64
},
{
"country": "China",
"year": "2015",
"cards": 75
},
{
"country": "Cuba",
"year": "2015",
"cards": 54
},
{
"country": "Dominican Rep",
"year": "2015",
"cards": 51
},
{
"country": "Philippines",
"year": "2015",
"cards": 56
},
{
"country": "Mexico",
"year": "2016",
"cards": 175
},
{
"country": "India",
"year": "2016",
"cards": 65
},
{
"country": "China",
"year": "2016",
"cards": 82
},
{
"country": "Cuba",
"year": "2016",
"cards": 67
},
{
"country": "Dominican Rep",
"year": "2016",
"cards": 61
},
{
"country": "Philippines",
"year": "2016",
"cards": 53
},
{
"country": "Mexico",
"year": "2017",
"cards": 171
},
{
"country": "India",
"year": "2017",
"cards": 60
},
{
"country": "China",
"year": "2017",
"cards": 72
},
{
"country": "Cuba",
"year": "2017",
"cards": 65
},
{
"country": "Dominican Rep",
"year": "2017",
"cards": 59
},
{
"country": "Philippines",
"year": "2017",
"cards": 49
},
{
"country": "Mexico",
"year": "2018",
"cards": 162
},
{
"country": "India",
"year": "2018",
"cards": 60
},
{
"country": "China",
"year": "2018",
"cards": 65
},
{
"country": "Cuba",
"year": "2018",
"cards": 76
},
{
"country": "Dominican Rep",
"year": "2018",
"cards": 57
},
{
"country": "Philippines",
"year": "2018",
"cards": 47
},
{
"country": "Mexico",
"year": "2019",
"cards": 156
},
{
"country": "India",
"year": "2019",
"cards": 55
},
{
"country": "China",
"year": "2019",
"cards": 62
},
{
"country": "Cuba",
"year": "2019",
"cards": 42
},
{
"country": "Dominican Rep",
"year": "2019",
"cards": 50
},
{
"country": "Philippines",
"year": "2019",
"cards": 46
},
{
"country": "Mexico",
"year": "2020",
"cards": 100
},
{
"country": "India",
"year": "2020",
"cards": 46
},
{
"country": "China",
"year": "2020",
"cards": 41
},
{
"country": "Cuba",
"year": "2020",
"cards": 16
},
{
"country": "Dominican Rep",
"year": "2020",
"cards": 30
},
{
"country": "Philippines",
"year": "2020",
"cards": 25
},
{
"country": "Mexico",
"year": "2021",
"cards": 107
},
{
"country": "India",
"year": "2021",
"cards": 93
},
{
"country": "China",
"year": "2021",
"cards": 50
},
{
"country": "Cuba",
"year": "2021",
"cards": 23
},
{
"country": "Dominican Rep",
"year": "2021",
"cards": 25
},
{
"country": "Philippines",
"year": "2021",
"cards": 28
},
{
"country": "Mexico",
"year": "2022",
"cards": 139
},
{
"country": "India",
"year": "2022",
"cards": 127
},
{
"country": "China",
"year": "2022",
"cards": 68
},
{
"country": "Cuba",
"year": "2022",
"cards": 37
},
{
"country": "Dominican Rep",
"year": "2022",
"cards": 40
},
{
"country": "Philippines",
"year": "2022",
"cards": 36
},
{
"country": "Mexico",
"year": "2023",
"cards": 181
},
{
"country": "India",
"year": "2023",
"cards": 78
},
{
"country": "China",
"year": "2023",
"cards": 59
},
{
"country": "Cuba",
"year": "2023",
"cards": 82
},
{
"country": "Dominican Rep",
"year": "2023",
"cards": 69
},
{
"country": "Philippines",
"year": "2023",
"cards": 49
}
],
"encoding": {
"x": {
"field": "country",
"type": "nominal",
"sort": [
"Mexico",
"India",
"China",
"Cuba",
"Dominican Rep",
"Philippines"
]
},
"y": {
"field": "year",
"type": "nominal",
"sort": [
"2014",
"2015",
"2016",
"2017",
"2018",
"2019",
"2020",
"2021",
"2022",
"2023"
]
},
"color": {
"field": "cards",
"type": "quantitative",
"scale": {
"scheme": "blue"
},
"format": ",.0f"
}
}
},
{
"mark": {
"type": "text",
"fill": "#ffffff",
"fontSize": 12
},
"transform": [
{
"filter": {
"field": "cards",
"gte": 150
}
}
],
"data": [
{
"country": "Mexico",
"year": "2014",
"cards": 134
},
{
"country": "India",
"year": "2014",
"cards": 78
},
{
"country": "China",
"year": "2014",
"cards": 76
},
{
"country": "Cuba",
"year": "2014",
"cards": 47
},
{
"country": "Dominican Rep",
"year": "2014",
"cards": 45
},
{
"country": "Philippines",
"year": "2014",
"cards": 50
},
{
"country": "Mexico",
"year": "2015",
"cards": 159
},
{
"country": "India",
"year": "2015",
"cards": 64
},
{
"country": "China",
"year": "2015",
"cards": 75
},
{
"country": "Cuba",
"year": "2015",
"cards": 54
},
{
"country": "Dominican Rep",
"year": "2015",
"cards": 51
},
{
"country": "Philippines",
"year": "2015",
"cards": 56
},
{
"country": "Mexico",
"year": "2016",
"cards": 175
},
{
"country": "India",
"year": "2016",
"cards": 65
},
{
"country": "China",
"year": "2016",
"cards": 82
},
{
"country": "Cuba",
"year": "2016",
"cards": 67
},
{
"country": "Dominican Rep",
"year": "2016",
"cards": 61
},
{
"country": "Philippines",
"year": "2016",
"cards": 53
},
{
"country": "Mexico",
"year": "2017",
"cards": 171
},
{
"country": "India",
"year": "2017",
"cards": 60
},
{
"country": "China",
"year": "2017",
"cards": 72
},
{
"country": "Cuba",
"year": "2017",
"cards": 65
},
{
"country": "Dominican Rep",
"year": "2017",
"cards": 59
},
{
"country": "Philippines",
"year": "2017",
"cards": 49
},
{
"country": "Mexico",
"year": "2018",
"cards": 162
},
{
"country": "India",
"year": "2018",
"cards": 60
},
{
"country": "China",
"year": "2018",
"cards": 65
},
{
"country": "Cuba",
"year": "2018",
"cards": 76
},
{
"country": "Dominican Rep",
"year": "2018",
"cards": 57
},
{
"country": "Philippines",
"year": "2018",
"cards": 47
},
{
"country": "Mexico",
"year": "2019",
"cards": 156
},
{
"country": "India",
"year": "2019",
"cards": 55
},
{
"country": "China",
"year": "2019",
"cards": 62
},
{
"country": "Cuba",
"year": "2019",
"cards": 42
},
{
"country": "Dominican Rep",
"year": "2019",
"cards": 50
},
{
"country": "Philippines",
"year": "2019",
"cards": 46
},
{
"country": "Mexico",
"year": "2020",
"cards": 100
},
{
"country": "India",
"year": "2020",
"cards": 46
},
{
"country": "China",
"year": "2020",
"cards": 41
},
{
"country": "Cuba",
"year": "2020",
"cards": 16
},
{
"country": "Dominican Rep",
"year": "2020",
"cards": 30
},
{
"country": "Philippines",
"year": "2020",
"cards": 25
},
{
"country": "Mexico",
"year": "2021",
"cards": 107
},
{
"country": "India",
"year": "2021",
"cards": 93
},
{
"country": "China",
"year": "2021",
"cards": 50
},
{
"country": "Cuba",
"year": "2021",
"cards": 23
},
{
"country": "Dominican Rep",
"year": "2021",
"cards": 25
},
{
"country": "Philippines",
"year": "2021",
"cards": 28
},
{
"country": "Mexico",
"year": "2022",
"cards": 139
},
{
"country": "India",
"year": "2022",
"cards": 127
},
{
"country": "China",
"year": "2022",
"cards": 68
},
{
"country": "Cuba",
"year": "2022",
"cards": 37
},
{
"country": "Dominican Rep",
"year": "2022",
"cards": 40
},
{
"country": "Philippines",
"year": "2022",
"cards": 36
},
{
"country": "Mexico",
"year": "2023",
"cards": 181
},
{
"country": "India",
"year": "2023",
"cards": 78
},
{
"country": "China",
"year": "2023",
"cards": 59
},
{
"country": "Cuba",
"year": "2023",
"cards": 82
},
{
"country": "Dominican Rep",
"year": "2023",
"cards": 69
},
{
"country": "Philippines",
"year": "2023",
"cards": 49
}
],
"encoding": {
"x": {
"field": "country",
"type": "nominal",
"sort": [
"Mexico",
"India",
"China",
"Cuba",
"Dominican Rep",
"Philippines"
]
},
"y": {
"field": "year",
"type": "nominal",
"sort": [
"2014",
"2015",
"2016",
"2017",
"2018",
"2019",
"2020",
"2021",
"2022",
"2023"
]
},
"text": {
"field": "cards",
"type": "quantitative"
}
}
},
{
"mark": {
"type": "text",
"fill": "#0f172a",
"fontSize": 12
},
"transform": [
{
"filter": {
"field": "cards",
"lt": 150
}
}
],
"data": [
{
"country": "Mexico",
"year": "2014",
"cards": 134
},
{
"country": "India",
"year": "2014",
"cards": 78
},
{
"country": "China",
"year": "2014",
"cards": 76
},
{
"country": "Cuba",
"year": "2014",
"cards": 47
},
{
"country": "Dominican Rep",
"year": "2014",
"cards": 45
},
{
"country": "Philippines",
"year": "2014",
"cards": 50
},
{
"country": "Mexico",
"year": "2015",
"cards": 159
},
{
"country": "India",
"year": "2015",
"cards": 64
},
{
"country": "China",
"year": "2015",
"cards": 75
},
{
"country": "Cuba",
"year": "2015",
"cards": 54
},
{
"country": "Dominican Rep",
"year": "2015",
"cards": 51
},
{
"country": "Philippines",
"year": "2015",
"cards": 56
},
{
"country": "Mexico",
"year": "2016",
"cards": 175
},
{
"country": "India",
"year": "2016",
"cards": 65
},
{
"country": "China",
"year": "2016",
"cards": 82
},
{
"country": "Cuba",
"year": "2016",
"cards": 67
},
{
"country": "Dominican Rep",
"year": "2016",
"cards": 61
},
{
"country": "Philippines",
"year": "2016",
"cards": 53
},
{
"country": "Mexico",
"year": "2017",
"cards": 171
},
{
"country": "India",
"year": "2017",
"cards": 60
},
{
"country": "China",
"year": "2017",
"cards": 72
},
{
"country": "Cuba",
"year": "2017",
"cards": 65
},
{
"country": "Dominican Rep",
"year": "2017",
"cards": 59
},
{
"country": "Philippines",
"year": "2017",
"cards": 49
},
{
"country": "Mexico",
"year": "2018",
"cards": 162
},
{
"country": "India",
"year": "2018",
"cards": 60
},
{
"country": "China",
"year": "2018",
"cards": 65
},
{
"country": "Cuba",
"year": "2018",
"cards": 76
},
{
"country": "Dominican Rep",
"year": "2018",
"cards": 57
},
{
"country": "Philippines",
"year": "2018",
"cards": 47
},
{
"country": "Mexico",
"year": "2019",
"cards": 156
},
{
"country": "India",
"year": "2019",
"cards": 55
},
{
"country": "China",
"year": "2019",
"cards": 62
},
{
"country": "Cuba",
"year": "2019",
"cards": 42
},
{
"country": "Dominican Rep",
"year": "2019",
"cards": 50
},
{
"country": "Philippines",
"year": "2019",
"cards": 46
},
{
"country": "Mexico",
"year": "2020",
"cards": 100
},
{
"country": "India",
"year": "2020",
"cards": 46
},
{
"country": "China",
"year": "2020",
"cards": 41
},
{
"country": "Cuba",
"year": "2020",
"cards": 16
},
{
"country": "Dominican Rep",
"year": "2020",
"cards": 30
},
{
"country": "Philippines",
"year": "2020",
"cards": 25
},
{
"country": "Mexico",
"year": "2021",
"cards": 107
},
{
"country": "India",
"year": "2021",
"cards": 93
},
{
"country": "China",
"year": "2021",
"cards": 50
},
{
"country": "Cuba",
"year": "2021",
"cards": 23
},
{
"country": "Dominican Rep",
"year": "2021",
"cards": 25
},
{
"country": "Philippines",
"year": "2021",
"cards": 28
},
{
"country": "Mexico",
"year": "2022",
"cards": 139
},
{
"country": "India",
"year": "2022",
"cards": 127
},
{
"country": "China",
"year": "2022",
"cards": 68
},
{
"country": "Cuba",
"year": "2022",
"cards": 37
},
{
"country": "Dominican Rep",
"year": "2022",
"cards": 40
},
{
"country": "Philippines",
"year": "2022",
"cards": 36
},
{
"country": "Mexico",
"year": "2023",
"cards": 181
},
{
"country": "India",
"year": "2023",
"cards": 78
},
{
"country": "China",
"year": "2023",
"cards": 59
},
{
"country": "Cuba",
"year": "2023",
"cards": 82
},
{
"country": "Dominican Rep",
"year": "2023",
"cards": 69
},
{
"country": "Philippines",
"year": "2023",
"cards": 49
}
],
"encoding": {
"x": {
"field": "country",
"type": "nominal",
"sort": [
"Mexico",
"India",
"China",
"Cuba",
"Dominican Rep",
"Philippines"
]
},
"y": {
"field": "year",
"type": "nominal",
"sort": [
"2014",
"2015",
"2016",
"2017",
"2018",
"2019",
"2020",
"2021",
"2022",
"2023"
]
},
"text": {
"field": "cards",
"type": "quantitative"
}
}
}
],
"chrome": {
"title": "Green cards fell 31% in fiscal 2020, with drops for all six countries",
"subtitle": "New green-card holders by country of birth and fiscal year, in thousands"
}
};
</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": "rect",
"data": [
{
"country": "Mexico",
"year": "2014",
"cards": 134
},
{
"country": "India",
"year": "2014",
"cards": 78
},
{
"country": "China",
"year": "2014",
"cards": 76
},
{
"country": "Cuba",
"year": "2014",
"cards": 47
},
{
"country": "Dominican Rep",
"year": "2014",
"cards": 45
},
{
"country": "Philippines",
"year": "2014",
"cards": 50
},
{
"country": "Mexico",
"year": "2015",
"cards": 159
},
{
"country": "India",
"year": "2015",
"cards": 64
},
{
"country": "China",
"year": "2015",
"cards": 75
},
{
"country": "Cuba",
"year": "2015",
"cards": 54
},
{
"country": "Dominican Rep",
"year": "2015",
"cards": 51
},
{
"country": "Philippines",
"year": "2015",
"cards": 56
},
{
"country": "Mexico",
"year": "2016",
"cards": 175
},
{
"country": "India",
"year": "2016",
"cards": 65
},
{
"country": "China",
"year": "2016",
"cards": 82
},
{
"country": "Cuba",
"year": "2016",
"cards": 67
},
{
"country": "Dominican Rep",
"year": "2016",
"cards": 61
},
{
"country": "Philippines",
"year": "2016",
"cards": 53
},
{
"country": "Mexico",
"year": "2017",
"cards": 171
},
{
"country": "India",
"year": "2017",
"cards": 60
},
{
"country": "China",
"year": "2017",
"cards": 72
},
{
"country": "Cuba",
"year": "2017",
"cards": 65
},
{
"country": "Dominican Rep",
"year": "2017",
"cards": 59
},
{
"country": "Philippines",
"year": "2017",
"cards": 49
},
{
"country": "Mexico",
"year": "2018",
"cards": 162
},
{
"country": "India",
"year": "2018",
"cards": 60
},
{
"country": "China",
"year": "2018",
"cards": 65
},
{
"country": "Cuba",
"year": "2018",
"cards": 76
},
{
"country": "Dominican Rep",
"year": "2018",
"cards": 57
},
{
"country": "Philippines",
"year": "2018",
"cards": 47
},
{
"country": "Mexico",
"year": "2019",
"cards": 156
},
{
"country": "India",
"year": "2019",
"cards": 55
},
{
"country": "China",
"year": "2019",
"cards": 62
},
{
"country": "Cuba",
"year": "2019",
"cards": 42
},
{
"country": "Dominican Rep",
"year": "2019",
"cards": 50
},
{
"country": "Philippines",
"year": "2019",
"cards": 46
},
{
"country": "Mexico",
"year": "2020",
"cards": 100
},
{
"country": "India",
"year": "2020",
"cards": 46
},
{
"country": "China",
"year": "2020",
"cards": 41
},
{
"country": "Cuba",
"year": "2020",
"cards": 16
},
{
"country": "Dominican Rep",
"year": "2020",
"cards": 30
},
{
"country": "Philippines",
"year": "2020",
"cards": 25
},
{
"country": "Mexico",
"year": "2021",
"cards": 107
},
{
"country": "India",
"year": "2021",
"cards": 93
},
{
"country": "China",
"year": "2021",
"cards": 50
},
{
"country": "Cuba",
"year": "2021",
"cards": 23
},
{
"country": "Dominican Rep",
"year": "2021",
"cards": 25
},
{
"country": "Philippines",
"year": "2021",
"cards": 28
},
{
"country": "Mexico",
"year": "2022",
"cards": 139
},
{
"country": "India",
"year": "2022",
"cards": 127
},
{
"country": "China",
"year": "2022",
"cards": 68
},
{
"country": "Cuba",
"year": "2022",
"cards": 37
},
{
"country": "Dominican Rep",
"year": "2022",
"cards": 40
},
{
"country": "Philippines",
"year": "2022",
"cards": 36
},
{
"country": "Mexico",
"year": "2023",
"cards": 181
},
{
"country": "India",
"year": "2023",
"cards": 78
},
{
"country": "China",
"year": "2023",
"cards": 59
},
{
"country": "Cuba",
"year": "2023",
"cards": 82
},
{
"country": "Dominican Rep",
"year": "2023",
"cards": 69
},
{
"country": "Philippines",
"year": "2023",
"cards": 49
}
],
"encoding": {
"x": {
"field": "country",
"type": "nominal",
"sort": [
"Mexico",
"India",
"China",
"Cuba",
"Dominican Rep",
"Philippines"
]
},
"y": {
"field": "year",
"type": "nominal",
"sort": [
"2014",
"2015",
"2016",
"2017",
"2018",
"2019",
"2020",
"2021",
"2022",
"2023"
]
},
"color": {
"field": "cards",
"type": "quantitative",
"scale": {
"scheme": "blue"
},
"format": ",.0f"
}
}
},
{
"mark": {
"type": "text",
"fill": "#ffffff",
"fontSize": 12
},
"transform": [
{
"filter": {
"field": "cards",
"gte": 150
}
}
],
"data": [
{
"country": "Mexico",
"year": "2014",
"cards": 134
},
{
"country": "India",
"year": "2014",
"cards": 78
},
{
"country": "China",
"year": "2014",
"cards": 76
},
{
"country": "Cuba",
"year": "2014",
"cards": 47
},
{
"country": "Dominican Rep",
"year": "2014",
"cards": 45
},
{
"country": "Philippines",
"year": "2014",
"cards": 50
},
{
"country": "Mexico",
"year": "2015",
"cards": 159
},
{
"country": "India",
"year": "2015",
"cards": 64
},
{
"country": "China",
"year": "2015",
"cards": 75
},
{
"country": "Cuba",
"year": "2015",
"cards": 54
},
{
"country": "Dominican Rep",
"year": "2015",
"cards": 51
},
{
"country": "Philippines",
"year": "2015",
"cards": 56
},
{
"country": "Mexico",
"year": "2016",
"cards": 175
},
{
"country": "India",
"year": "2016",
"cards": 65
},
{
"country": "China",
"year": "2016",
"cards": 82
},
{
"country": "Cuba",
"year": "2016",
"cards": 67
},
{
"country": "Dominican Rep",
"year": "2016",
"cards": 61
},
{
"country": "Philippines",
"year": "2016",
"cards": 53
},
{
"country": "Mexico",
"year": "2017",
"cards": 171
},
{
"country": "India",
"year": "2017",
"cards": 60
},
{
"country": "China",
"year": "2017",
"cards": 72
},
{
"country": "Cuba",
"year": "2017",
"cards": 65
},
{
"country": "Dominican Rep",
"year": "2017",
"cards": 59
},
{
"country": "Philippines",
"year": "2017",
"cards": 49
},
{
"country": "Mexico",
"year": "2018",
"cards": 162
},
{
"country": "India",
"year": "2018",
"cards": 60
},
{
"country": "China",
"year": "2018",
"cards": 65
},
{
"country": "Cuba",
"year": "2018",
"cards": 76
},
{
"country": "Dominican Rep",
"year": "2018",
"cards": 57
},
{
"country": "Philippines",
"year": "2018",
"cards": 47
},
{
"country": "Mexico",
"year": "2019",
"cards": 156
},
{
"country": "India",
"year": "2019",
"cards": 55
},
{
"country": "China",
"year": "2019",
"cards": 62
},
{
"country": "Cuba",
"year": "2019",
"cards": 42
},
{
"country": "Dominican Rep",
"year": "2019",
"cards": 50
},
{
"country": "Philippines",
"year": "2019",
"cards": 46
},
{
"country": "Mexico",
"year": "2020",
"cards": 100
},
{
"country": "India",
"year": "2020",
"cards": 46
},
{
"country": "China",
"year": "2020",
"cards": 41
},
{
"country": "Cuba",
"year": "2020",
"cards": 16
},
{
"country": "Dominican Rep",
"year": "2020",
"cards": 30
},
{
"country": "Philippines",
"year": "2020",
"cards": 25
},
{
"country": "Mexico",
"year": "2021",
"cards": 107
},
{
"country": "India",
"year": "2021",
"cards": 93
},
{
"country": "China",
"year": "2021",
"cards": 50
},
{
"country": "Cuba",
"year": "2021",
"cards": 23
},
{
"country": "Dominican Rep",
"year": "2021",
"cards": 25
},
{
"country": "Philippines",
"year": "2021",
"cards": 28
},
{
"country": "Mexico",
"year": "2022",
"cards": 139
},
{
"country": "India",
"year": "2022",
"cards": 127
},
{
"country": "China",
"year": "2022",
"cards": 68
},
{
"country": "Cuba",
"year": "2022",
"cards": 37
},
{
"country": "Dominican Rep",
"year": "2022",
"cards": 40
},
{
"country": "Philippines",
"year": "2022",
"cards": 36
},
{
"country": "Mexico",
"year": "2023",
"cards": 181
},
{
"country": "India",
"year": "2023",
"cards": 78
},
{
"country": "China",
"year": "2023",
"cards": 59
},
{
"country": "Cuba",
"year": "2023",
"cards": 82
},
{
"country": "Dominican Rep",
"year": "2023",
"cards": 69
},
{
"country": "Philippines",
"year": "2023",
"cards": 49
}
],
"encoding": {
"x": {
"field": "country",
"type": "nominal",
"sort": [
"Mexico",
"India",
"China",
"Cuba",
"Dominican Rep",
"Philippines"
]
},
"y": {
"field": "year",
"type": "nominal",
"sort": [
"2014",
"2015",
"2016",
"2017",
"2018",
"2019",
"2020",
"2021",
"2022",
"2023"
]
},
"text": {
"field": "cards",
"type": "quantitative"
}
}
},
{
"mark": {
"type": "text",
"fill": "#0f172a",
"fontSize": 12
},
"transform": [
{
"filter": {
"field": "cards",
"lt": 150
}
}
],
"data": [
{
"country": "Mexico",
"year": "2014",
"cards": 134
},
{
"country": "India",
"year": "2014",
"cards": 78
},
{
"country": "China",
"year": "2014",
"cards": 76
},
{
"country": "Cuba",
"year": "2014",
"cards": 47
},
{
"country": "Dominican Rep",
"year": "2014",
"cards": 45
},
{
"country": "Philippines",
"year": "2014",
"cards": 50
},
{
"country": "Mexico",
"year": "2015",
"cards": 159
},
{
"country": "India",
"year": "2015",
"cards": 64
},
{
"country": "China",
"year": "2015",
"cards": 75
},
{
"country": "Cuba",
"year": "2015",
"cards": 54
},
{
"country": "Dominican Rep",
"year": "2015",
"cards": 51
},
{
"country": "Philippines",
"year": "2015",
"cards": 56
},
{
"country": "Mexico",
"year": "2016",
"cards": 175
},
{
"country": "India",
"year": "2016",
"cards": 65
},
{
"country": "China",
"year": "2016",
"cards": 82
},
{
"country": "Cuba",
"year": "2016",
"cards": 67
},
{
"country": "Dominican Rep",
"year": "2016",
"cards": 61
},
{
"country": "Philippines",
"year": "2016",
"cards": 53
},
{
"country": "Mexico",
"year": "2017",
"cards": 171
},
{
"country": "India",
"year": "2017",
"cards": 60
},
{
"country": "China",
"year": "2017",
"cards": 72
},
{
"country": "Cuba",
"year": "2017",
"cards": 65
},
{
"country": "Dominican Rep",
"year": "2017",
"cards": 59
},
{
"country": "Philippines",
"year": "2017",
"cards": 49
},
{
"country": "Mexico",
"year": "2018",
"cards": 162
},
{
"country": "India",
"year": "2018",
"cards": 60
},
{
"country": "China",
"year": "2018",
"cards": 65
},
{
"country": "Cuba",
"year": "2018",
"cards": 76
},
{
"country": "Dominican Rep",
"year": "2018",
"cards": 57
},
{
"country": "Philippines",
"year": "2018",
"cards": 47
},
{
"country": "Mexico",
"year": "2019",
"cards": 156
},
{
"country": "India",
"year": "2019",
"cards": 55
},
{
"country": "China",
"year": "2019",
"cards": 62
},
{
"country": "Cuba",
"year": "2019",
"cards": 42
},
{
"country": "Dominican Rep",
"year": "2019",
"cards": 50
},
{
"country": "Philippines",
"year": "2019",
"cards": 46
},
{
"country": "Mexico",
"year": "2020",
"cards": 100
},
{
"country": "India",
"year": "2020",
"cards": 46
},
{
"country": "China",
"year": "2020",
"cards": 41
},
{
"country": "Cuba",
"year": "2020",
"cards": 16
},
{
"country": "Dominican Rep",
"year": "2020",
"cards": 30
},
{
"country": "Philippines",
"year": "2020",
"cards": 25
},
{
"country": "Mexico",
"year": "2021",
"cards": 107
},
{
"country": "India",
"year": "2021",
"cards": 93
},
{
"country": "China",
"year": "2021",
"cards": 50
},
{
"country": "Cuba",
"year": "2021",
"cards": 23
},
{
"country": "Dominican Rep",
"year": "2021",
"cards": 25
},
{
"country": "Philippines",
"year": "2021",
"cards": 28
},
{
"country": "Mexico",
"year": "2022",
"cards": 139
},
{
"country": "India",
"year": "2022",
"cards": 127
},
{
"country": "China",
"year": "2022",
"cards": 68
},
{
"country": "Cuba",
"year": "2022",
"cards": 37
},
{
"country": "Dominican Rep",
"year": "2022",
"cards": 40
},
{
"country": "Philippines",
"year": "2022",
"cards": 36
},
{
"country": "Mexico",
"year": "2023",
"cards": 181
},
{
"country": "India",
"year": "2023",
"cards": 78
},
{
"country": "China",
"year": "2023",
"cards": 59
},
{
"country": "Cuba",
"year": "2023",
"cards": 82
},
{
"country": "Dominican Rep",
"year": "2023",
"cards": 69
},
{
"country": "Philippines",
"year": "2023",
"cards": 49
}
],
"encoding": {
"x": {
"field": "country",
"type": "nominal",
"sort": [
"Mexico",
"India",
"China",
"Cuba",
"Dominican Rep",
"Philippines"
]
},
"y": {
"field": "year",
"type": "nominal",
"sort": [
"2014",
"2015",
"2016",
"2017",
"2018",
"2019",
"2020",
"2021",
"2022",
"2023"
]
},
"text": {
"field": "cards",
"type": "quantitative"
}
}
}
],
"chrome": {
"title": "Green cards fell 31% in fiscal 2020, with drops for all six countries",
"subtitle": "New green-card holders by country of birth and fiscal year, in thousands"
}
};
const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);
Mexico is the darkest column in every year. Fiscal 2020 (October 2019 to September 2020) is a pale row across every country, and fiscal 2021 stays pale for every country but India.
With 60 cells, each cell carries its number, so the reader can check a color against a value. At several hundred cells the labels would crowd each other, and the color and the hover tooltip would have to carry the numbers. Six columns also leave a phone room for a three-digit number in each cell.
Sequential or diverging color
A sequential scale runs from light to dark in one hue, and fits values that only go one way, like counts. A diverging scale runs two hues out from a neutral middle, and fits values that sit above or below a reference point.
A color scale spent on the long-term trend hides the seasonal one. Mauna Loa Observatory in Hawaii has measured carbon dioxide (CO2) in the air every month since 1958, and NOAA publishes the readings through its Global Monitoring Laboratory. Each row below is every fifth year from 1960 and each column one month, on a single sequential scale.
Made with OpenChart. How to build this heatmap
{
"mark": "rect",
"data": [
{
"year": "1960",
"month": "Jan",
"ppm": 316.43
},
{
"year": "1960",
"month": "Feb",
"ppm": 316.98
},
{
"year": "1960",
"month": "Mar",
"ppm": 317.58
},
{
"year": "1960",
"month": "Apr",
"ppm": 319.03
},
{
"year": "1960",
"month": "May",
"ppm": 320.03
},
{
"year": "1960",
"month": "Jun",
"ppm": 319.58
},
// … 162 more rows; Copy includes them
],
"encoding": {
"x": {
"field": "month",
"type": "nominal",
"sort": [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
]
},
"y": {
"field": "year",
"type": "nominal",
"sort": [
"1960",
"1965",
"1970",
"1975",
"1980",
"1985",
"1990",
"1995",
"2000",
"2005",
"2010",
"2015",
"2020",
"2025"
]
},
"color": {
"field": "ppm",
"type": "quantitative",
"scale": {
"scheme": "blue"
},
"format": ".1f"
}
},
"overrides": {
"compact": {
"encoding": {
"x": {
"axis": {
"values": [
"Jan",
"Mar",
"May",
"Jul",
"Sep",
"Nov"
],
"labelAngle": 0
}
}
}
}
},
"chrome": {
"title": "The lowest month of 2025 was 104 ppm above the highest month of 1960",
"subtitle": "Monthly mean CO2 at Mauna Loa, every fifth year from 1960, parts per million"
}
}import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 168 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "rect",
"encoding": {
"x": {
"field": "month",
"type": "nominal",
"sort": [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
]
},
"y": {
"field": "year",
"type": "nominal",
"sort": [
"1960",
"1965",
"1970",
"1975",
"1980",
"1985",
"1990",
"1995",
"2000",
"2005",
"2010",
"2015",
"2020",
"2025"
]
},
"color": {
"field": "ppm",
"type": "quantitative",
"scale": {
"scheme": "blue"
},
"format": ".1f"
}
},
"overrides": {
"compact": {
"encoding": {
"x": {
"axis": {
"values": [
"Jan",
"Mar",
"May",
"Jul",
"Sep",
"Nov"
],
"labelAngle": 0
}
}
}
}
},
"chrome": {
"title": "The lowest month of 2025 was 104 ppm above the highest month of 1960",
"subtitle": "Monthly mean CO2 at Mauna Loa, every fifth year from 1960, parts per million"
}
};
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 = [/* 168 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "rect",
"encoding": {
"x": {
"field": "month",
"type": "nominal",
"sort": [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
]
},
"y": {
"field": "year",
"type": "nominal",
"sort": [
"1960",
"1965",
"1970",
"1975",
"1980",
"1985",
"1990",
"1995",
"2000",
"2005",
"2010",
"2015",
"2020",
"2025"
]
},
"color": {
"field": "ppm",
"type": "quantitative",
"scale": {
"scheme": "blue"
},
"format": ".1f"
}
},
"overrides": {
"compact": {
"encoding": {
"x": {
"axis": {
"values": [
"Jan",
"Mar",
"May",
"Jul",
"Sep",
"Nov"
],
"labelAngle": 0
}
}
}
}
},
"chrome": {
"title": "The lowest month of 2025 was 104 ppm above the highest month of 1960",
"subtitle": "Monthly mean CO2 at Mauna Loa, every fifth year from 1960, parts per million"
}
};
</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 = [/* 168 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "rect",
"encoding": {
"x": {
"field": "month",
"type": "nominal",
"sort": [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
]
},
"y": {
"field": "year",
"type": "nominal",
"sort": [
"1960",
"1965",
"1970",
"1975",
"1980",
"1985",
"1990",
"1995",
"2000",
"2005",
"2010",
"2015",
"2020",
"2025"
]
},
"color": {
"field": "ppm",
"type": "quantitative",
"scale": {
"scheme": "blue"
},
"format": ".1f"
}
},
"overrides": {
"compact": {
"encoding": {
"x": {
"axis": {
"values": [
"Jan",
"Mar",
"May",
"Jul",
"Sep",
"Nov"
],
"labelAngle": 0
}
}
}
}
},
"chrome": {
"title": "The lowest month of 2025 was 104 ppm above the highest month of 1960",
"subtitle": "Monthly mean CO2 at Mauna Loa, every fifth year from 1960, parts per million"
}
};
</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 = [/* 168 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "rect",
"encoding": {
"x": {
"field": "month",
"type": "nominal",
"sort": [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
]
},
"y": {
"field": "year",
"type": "nominal",
"sort": [
"1960",
"1965",
"1970",
"1975",
"1980",
"1985",
"1990",
"1995",
"2000",
"2005",
"2010",
"2015",
"2020",
"2025"
]
},
"color": {
"field": "ppm",
"type": "quantitative",
"scale": {
"scheme": "blue"
},
"format": ".1f"
}
},
"overrides": {
"compact": {
"encoding": {
"x": {
"axis": {
"values": [
"Jan",
"Mar",
"May",
"Jul",
"Sep",
"Nov"
],
"labelAngle": 0
}
}
}
}
},
"chrome": {
"title": "The lowest month of 2025 was 104 ppm above the highest month of 1960",
"subtitle": "Monthly mean CO2 at Mauna Loa, every fifth year from 1960, parts per million"
}
};
const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);
The rows get darker from 1960 to 2025 and nothing else shows. CO2 climbed by more than 100 parts per million (ppm) between those years, so the trend uses up the whole color range.
Within each year CO2 also rises and falls with the seasons. It builds up over the winter, peaks in spring, and falls to its low in early autumn as northern-hemisphere plants take it up through the summer growing season. That swing is about 5 to 6 ppm, too small to see against 100. Subtracting each year’s own average removes the trend and centers the scale on zero, which makes a diverging scale the right one.
Made with OpenChart. How to build this heatmap
{
"mark": "rect",
"data": [
{
"year": "1960",
"month": "Jan",
"departure": -0.5
},
{
"year": "1960",
"month": "Feb",
"departure": 0.1
},
{
"year": "1960",
"month": "Mar",
"departure": 0.7
},
{
"year": "1960",
"month": "Apr",
"departure": 2.1
},
{
"year": "1960",
"month": "May",
"departure": 3.1
},
{
"year": "1960",
"month": "Jun",
"departure": 2.7
},
// … 162 more rows; Copy includes them
],
"encoding": {
"x": {
"field": "month",
"type": "nominal",
"sort": [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
]
},
"y": {
"field": "year",
"type": "nominal",
"sort": [
"1960",
"1965",
"1970",
"1975",
"1980",
"1985",
"1990",
"1995",
"2000",
"2005",
"2010",
"2015",
"2020",
"2025"
]
},
"color": {
"field": "departure",
"type": "quantitative",
"scale": {
"scheme": "redBlue",
"domain": [
-4,
4
],
"reverse": true
},
"format": ".1f"
}
},
"overrides": {
"compact": {
"encoding": {
"x": {
"axis": {
"values": [
"Jan",
"Mar",
"May",
"Jul",
"Sep",
"Nov"
],
"labelAngle": 0
}
}
}
}
},
"chrome": {
"title": "CO2 peaks in spring and is lowest in autumn every year",
"subtitle": "Monthly mean CO2 at Mauna Loa, difference from that year's average, ppm"
}
}import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 168 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "rect",
"encoding": {
"x": {
"field": "month",
"type": "nominal",
"sort": [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
]
},
"y": {
"field": "year",
"type": "nominal",
"sort": [
"1960",
"1965",
"1970",
"1975",
"1980",
"1985",
"1990",
"1995",
"2000",
"2005",
"2010",
"2015",
"2020",
"2025"
]
},
"color": {
"field": "departure",
"type": "quantitative",
"scale": {
"scheme": "redBlue",
"domain": [
-4,
4
],
"reverse": true
},
"format": ".1f"
}
},
"overrides": {
"compact": {
"encoding": {
"x": {
"axis": {
"values": [
"Jan",
"Mar",
"May",
"Jul",
"Sep",
"Nov"
],
"labelAngle": 0
}
}
}
}
},
"chrome": {
"title": "CO2 peaks in spring and is lowest in autumn every year",
"subtitle": "Monthly mean CO2 at Mauna Loa, difference from that year's average, ppm"
}
};
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 = [/* 168 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "rect",
"encoding": {
"x": {
"field": "month",
"type": "nominal",
"sort": [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
]
},
"y": {
"field": "year",
"type": "nominal",
"sort": [
"1960",
"1965",
"1970",
"1975",
"1980",
"1985",
"1990",
"1995",
"2000",
"2005",
"2010",
"2015",
"2020",
"2025"
]
},
"color": {
"field": "departure",
"type": "quantitative",
"scale": {
"scheme": "redBlue",
"domain": [
-4,
4
],
"reverse": true
},
"format": ".1f"
}
},
"overrides": {
"compact": {
"encoding": {
"x": {
"axis": {
"values": [
"Jan",
"Mar",
"May",
"Jul",
"Sep",
"Nov"
],
"labelAngle": 0
}
}
}
}
},
"chrome": {
"title": "CO2 peaks in spring and is lowest in autumn every year",
"subtitle": "Monthly mean CO2 at Mauna Loa, difference from that year's average, ppm"
}
};
</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 = [/* 168 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "rect",
"encoding": {
"x": {
"field": "month",
"type": "nominal",
"sort": [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
]
},
"y": {
"field": "year",
"type": "nominal",
"sort": [
"1960",
"1965",
"1970",
"1975",
"1980",
"1985",
"1990",
"1995",
"2000",
"2005",
"2010",
"2015",
"2020",
"2025"
]
},
"color": {
"field": "departure",
"type": "quantitative",
"scale": {
"scheme": "redBlue",
"domain": [
-4,
4
],
"reverse": true
},
"format": ".1f"
}
},
"overrides": {
"compact": {
"encoding": {
"x": {
"axis": {
"values": [
"Jan",
"Mar",
"May",
"Jul",
"Sep",
"Nov"
],
"labelAngle": 0
}
}
}
}
},
"chrome": {
"title": "CO2 peaks in spring and is lowest in autumn every year",
"subtitle": "Monthly mean CO2 at Mauna Loa, difference from that year's average, ppm"
}
};
</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 = [/* 168 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": "rect",
"encoding": {
"x": {
"field": "month",
"type": "nominal",
"sort": [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
]
},
"y": {
"field": "year",
"type": "nominal",
"sort": [
"1960",
"1965",
"1970",
"1975",
"1980",
"1985",
"1990",
"1995",
"2000",
"2005",
"2010",
"2015",
"2020",
"2025"
]
},
"color": {
"field": "departure",
"type": "quantitative",
"scale": {
"scheme": "redBlue",
"domain": [
-4,
4
],
"reverse": true
},
"format": ".1f"
}
},
"overrides": {
"compact": {
"encoding": {
"x": {
"axis": {
"values": [
"Jan",
"Mar",
"May",
"Jul",
"Sep",
"Nov"
],
"labelAngle": 0
}
}
}
}
},
"chrome": {
"title": "CO2 peaks in spring and is lowest in autumn every year",
"subtitle": "Monthly mean CO2 at Mauna Loa, difference from that year's average, ppm"
}
};
const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);
Now the same months are red or blue in every year: spring is red and autumn is blue, so the stripes run down the columns.
Row and column order
A heatmap reads by adjacency, so the order of the categories is part of the chart. OpenChart keeps categories in the order they appear in the data, so data sorted alphabetically puts April next to August. Both CO2 charts list the months in calendar order and the years in time order with a sort array. The green card chart orders countries by size, so the darkest column is on the left.
When no natural order exists, sort the rows by their average value. Rows with similar levels then sit together and the blocks of color are easier to see.
When to use a line chart instead
Fourteen years of twelve months would be fourteen tangled lines on a shared month axis, while the grid gives each year its own row. Below about five rows, lines show a seasonal cycle as well as a grid does, and they show the size of each swing, which color only hints at. For two numbers per observation, use a scatter plot.
The spec
A heatmap is the rect mark. Put one category on encoding.x and the other on encoding.y, both nominal, and a quantitative field on encoding.color. A sort array on a nominal channel lists the categories in order, from top to bottom for y.
On color, scale.scheme picks the ramp: "blue" is sequential and "redBlue" is diverging. scale.domain: [-4, 4] centers the neutral color on zero, and reverse: true flips redBlue so positive values are red. format sets how values print in the tooltip and the legend. See the color guide and the scales guide for the other options.
On a phone, twelve month names would rotate to fit. overrides.compact sets the x axis values to every other month and labelAngle: 0, so the labels stay level.
The cell numbers in the green card chart are two extra layers of text marks drawn over the rect layer with the same data and the same x and y. One layer filters to cells of 150 thousand or more and draws white text, and the other draws dark text on the rest, so every label keeps at least 4.5:1 contrast with its cell.
To try another color ramp or a fixed domain on a grid like these, start from the heatmap page.