Skip to content

Instantly share code, notes, and snippets.

@badosa
Last active August 29, 2022 13:28
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/ea20fed156ac8cf05b9054f4fa130d75 to your computer and use it in GitHub Desktop.
Save badosa/ea20fed156ac8cf05b9054f4fa130d75 to your computer and use it in GitHub Desktop.
EuroJSONstat: Unemployment Trend Comparison
<!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>Visual + JSON-stat: simple line chart</title>
<link href="https://bl.ocks.org/d/e3e065fe80f2b0084bef/style.css" rel="stylesheet" type="text/css" />
<!-- DO NOT DO THIS IN PRODUCTION -->
<!-- js.org IS NOT A CDN -->
<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 -->
<!-- Using JSONstat XHR capabilities require Promises and Fetch support. Polyfill included for IE, for example -->
<script src="https://cdn.jsdelivr.net/combine/npm/es6-promise@4.2.8,npm/whatwg-fetch@3.0.0,npm/jsonstat-toolkit@1.4.2,npm/jsonstat-euro@2.0.0"></script>
</head>
<body>
<h1></h1>
<form>
<select id="geo1"></select>
<select id="geo2"></select>
</form>
<div id="visual" class="visual"></div>
<script>
var
query={
dataset: "tesem120", //tesem120: Unemployment rate
filter: {
sex: ["T"],
age: ["Y15-74"],
unit: ["PC_ACT"]
}
}
;
EuroJSONstat.fetchDataset(query).then(function(ds){
var
html="",
egeo=[ document.getElementById("geo1"), document.getElementById("geo2") ],
title=document.getElementsByTagName("h1")[0],
time=ds.Dimension( "time" ).id,
geod=ds.Dimension( "geo" ),
draw=function( geo ){
var
label=[ geod.Category( geo[0] ).label, geod.Category( geo[1] ).label ],
val=[[],[]]
;
time.forEach(function(t){
val[0].push( ds.Data( { "time": t, "geo": geo[0] } ).value );
val[1].push( ds.Data( { "time": t, "geo": geo[1] } ).value );
});
title.innerHTML="Unemployment rate: " + label[0] + " <i>vs</i> " + label[1];
visual({
fixed: [ 960, 395],
lang: "en",
autoheading: false,
time: time,
unit: { label: "%" },
dec: 1,
range: [0, 30],
grid: {
line: 5,
shadow: 6,
point: 0
},
legend: false,
type: "tsline",
data: [
{ label: label[0], val: val[0] },
{ label: label[1], val: val[1] }
]
});
}
;
geod.id.forEach(function(e){
html+='<option value="'+e+'"'+'>'+geod.Category(e).label+'</option>';
});
egeo[0].innerHTML=html;
egeo[1].innerHTML=html;
var select=[
egeo[0].options[egeo[0].selectedIndex].value,
egeo[1].options[egeo[1].selectedIndex].value
];
draw( select );
[].forEach.call(document.getElementsByTagName("select"), function (e) {
e.addEventListener("change", function() {
select[ this.id.substr(3)-1 ]=this.options[this.selectedIndex].value;
draw( select );
}, false);
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment