Statistics Greenland allows you to save a query in the JSON-stat format. In this example, a saved query of a customized view of a Greenland's StatBank table. It also illustrates how to deal with providers that split the time dimension (in this example, there's a dimension for years and a different one for quarters).
Last active
November 20, 2019 20:23
-
-
Save badosa/8c1d7f29b5a6f6ee03eb to your computer and use it in GitHub Desktop.
Greenlandish Labor Market
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>Connecting to a PX-Web saved query</title> | |
<!-- DO NOT DO THIS IN PRODUCTION --> | |
<!-- js.org and json-stat.org ARE NOT CDNs! Link to your own copies or to a CDN. --> | |
<link href="https://visual.js.org/visual.css" rel="stylesheet" type="text/css" /> | |
<script src="https://cdn.jsdelivr.net/npm/jsonstat@0.13.13"></script> | |
<script src="https://visual.js.org/lazyvisualsetup.js"></script> | |
<!-- /DO NOT DO THIS IN PRODUCTION --> | |
</head> | |
<body> | |
<section id="visual" class="visual"></section> | |
<script> | |
var url="https://bank.stat.gl/sq/f5b581bb-d2de-4aa4-9d9e-1a304c68832c"; | |
//Saved query from http://bank.stat.gl/pxweb/en/Greenland/Greenland__AR__AR10/ARXSTK1.px/table/tableViewLayout1/?rxid=184a6b31-d86f-4eb0-a2ca-ce39f1f0b65b | |
//"time" && "quarter" contain time; "inventory variable", employment status | |
JSONstat( url, function(){ | |
var | |
statusid="inventory variable", | |
actid="0", //labor force id | |
emplid="1", //employment id | |
time=[], act=[], empl=[], | |
ds=this.Dataset(0), | |
status=ds.Dimension(statusid), | |
actlabel=status.Category(actid).label | |
; | |
ds.toTable({type:"arrobj"}).forEach(function(e){ | |
if(e[statusid]===actlabel){ | |
time.push(e.time + e.quarter.substring(0,1)); | |
act.push(e.value); | |
}else{ | |
empl.push(e.value); | |
} | |
}); | |
visual({ | |
lang: "en", | |
title: "Labour market", | |
geo: "Greenland", | |
time: time, | |
footer: "Source: " + ds.source + ".", | |
unit: {label: "people"}, | |
dec: 0, | |
grid: { | |
line: 5, | |
shadow: 6, | |
point: 0 | |
}, | |
type: "tsline", | |
data: [ | |
{ label: status.Category(actid).label, val: act }, | |
{ label: status.Category(emplid).label, val: empl } | |
] | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment