Skip to content

Instantly share code, notes, and snippets.

@badosa
Last active March 20, 2021 20:35
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/7199354 to your computer and use it in GitHub Desktop.
Save badosa/7199354 to your computer and use it in GitHub Desktop.
A Population Pyramid in a Couple of Lines of Code
<!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 + JSONP</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<!-- 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://cdn.jsdelivr.net/npm/jsonstat-toolkit@1.2.6"></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>
JSONstat("https://data.ssb.no/api/v0/dataset/1082.json?lang=en").then(function(j){
var
ds=j.Dataset(0),
time=ds.Dimension('Tid'),
latest=time.id[time.length-1]
; //End of line #1
visual({
lang: "en",
title: "Norwegian population pyramid",
geo: ds.Dimension("Region").Category(0).label,
time: latest,
footer: "Source: "+ds.source+".",
unit: { label: "people" },
axis: { y: false },
dec: 0,
type: "pyram",
by: ds.Dimension('Alder').Category().map(function(e){ return e.label; }),
data: [
{ label: "Men", val: ds.Data({'Kjonn': '1', 'Tid': latest}, false)},
{ label: "Women", val: ds.Data({'Kjonn': '2', 'Tid': latest}, false)}
]
}); //End of line #2
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment