The Spanish Statistical Office has its own JSON API but also supports JSON-stat. In this example, the latest Spanish unemployment rate by NUTS2 is retrieved and visualized in a map using Idescat Visual.
Created
October 2, 2022 17:11
-
-
Save badosa/73d6d471b42abc17ac01502024be5f28 to your computer and use it in GitHub Desktop.
Latest unemployment rate in Spain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<!--[if lt IE 7]><html class="lt-ie9 lt-ie8 lt-ie7"> <![endif]--> | |
<!--[if IE 7]><html class="lt-ie9 lt-ie8"> <![endif]--> | |
<!--[if IE 8]><html class="lt-ie9"> <![endif]--> | |
<!--[if gt IE 8]><!--> <html> <!--<![endif]--> | |
<head> | |
<title>INE JSON-stat API + Idescat Visual choropleth map example</title> | |
<!-- DO NOT DO THIS IN PRODUCTION --> | |
<!-- js.org and json-stat.org ARE NOT CDNs --> | |
<link href="https://visual.js.org/visual.css" rel="stylesheet" type="text/css" /> | |
<script src="https://visual.js.org/lazyvisualsetup.js"></script> | |
<!-- /DO NOT DO THIS IN PRODUCTION --> | |
<script src="https://unpkg.com/jsonstat-toolkit@latest"></script> | |
</head> | |
<body> | |
<div id="visual" class="visual"></div> | |
<script> | |
//Unemployment rate | |
JSONstat("https://servicios.ine.es/wstempus/jsstat/ES/DATASET/4247?nult=1").then(function(ds){ | |
//1. Get info | |
var | |
t=ds.Dimension("Per"), | |
//Get time id | |
last=t.id[0], | |
//Get countries IDs | |
nuts=ds.Dimension( "comunidadesyciudadesautonomas" ).id, | |
//Get the values for the selected time | |
//for all the countries (free dimension). | |
//Then transform info to the Visual data format | |
data=ds.Data( { "sexo": "sexo_ambossexos", "edad": "totalesdeedad_total" } ).map( function( e, i ){ | |
return { id: nuts[i].replace("CCAA_", ""), val: e.value }; | |
}) | |
; | |
//2. Draw map with retrieved and transformed info | |
visual( | |
{ | |
lang: "en", | |
title: "Latest unemployment rate", | |
time: last, | |
geo: "Spain", | |
footer: "Source: Labor Force Survey (EPA), INE.", | |
unit: { symbol: "%" }, | |
dec: 1, | |
legend: true, | |
range: 0, | |
type: "cmap", | |
by: "spainnuts2", | |
data: data | |
} | |
); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment