Skip to content

Instantly share code, notes, and snippets.

@badosa
Last active March 16, 2021 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save badosa/ca7dac1732876ad570f2d829d176e0ed to your computer and use it in GitHub Desktop.
Save badosa/ca7dac1732876ad570f2d829d176e0ed to your computer and use it in GitHub Desktop.
Tourists in the Canary Islands

The Canary Islands Statistics Institute (ISTAC) has several APIs. Its Indicators API does not support JSON-stat but uses a format that it's very similar to JSON-stat, meaning: it can be translated to JSON-stat in a few lines of code (function can2jsonstat() in the example).

This example uses a tourism indicator but should work with any indicator from ISTAC.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="/d/ed9665503abec4f542d1/style.css">
<script src="https://cdn.jsdelivr.net/combine/npm/jsonstat@0.13.13,npm/jsonstat-utils@2.5.5"></script>
</head>
<body>
<div id="tbrowser">Retrieving dataset...</div>
<script>
var
url="https://datos.canarias.es/api/estadisticas/indicators/v1.0/indicators/TURISTAS/data",
can2jsonstat=function(data){
var
id=data.format,
dimension={},
size=id.map(function(e){
return data.dimension[e].representation.size;
}),
value=data.observation.map(function(e){
return e==="." ? null : parseFloat(e);
})
;
id.forEach(function(e){
dimension[e]={
"category": {
"index": data.dimension[e].representation.index
}
};
});
return {
"version": "2.0",
"class": "dataset",
"value": value,
"id": id,
"size": size,
"dimension": dimension
};
}
;
fetch( url )
.then(function(resp) {
resp.json().then(function(json){
JSONstatUtils.tbrowser(
can2jsonstat(json),
document.getElementById("tbrowser"),
{
tblclass: "tbrowser"
}
);
});
})
;
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment