Skip to content

Instantly share code, notes, and snippets.

@badosa
Last active November 20, 2019 20:17
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/4ef0e6e7f0971e206f7d33d51b85a455 to your computer and use it in GitHub Desktop.
Save badosa/4ef0e6e7f0971e206f7d33d51b85a455 to your computer and use it in GitHub Desktop.
UK Unemployment by Sex

The data from UK's Office for National Statistics Labour Force Survey are retrieved using the NOMIS API and displayed with ChartJS.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="https://cdn.jsdelivr.net/npm/jsonstat@0.13.13"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.js"></script>
</head>
<body>
<div class="chart-container" style="position: relative; height:90vh; width:90vw">
<canvas id="chart"></canvas>
</div>
<script>
var
maleId="5",
femaleId="6",
url="https://www.nomisweb.co.uk/api/v01/dataset/NM_59_1.jsonstat.json?geography=2092957697&economic_activity=3&value_type=0&measures=20100&sex="+maleId+","+femaleId,
ctx=document.getElementById("chart").getContext("2d")
;
JSONstat(
url,
function(){
var
time=this.Dimension({role: "time"}, false)[0],
sex=this.Dimension("sex"),
myChart=new Chart(ctx, {
type: "line",
data: {
labels: time,
datasets: [{
label: sex.Category(maleId).label,
data: this.Data({sex: maleId}, false),
borderColor:"rgb(0, 0, 139)",
lineTension: 0,
fill: false,
pointRadius: 0
},
{
label: sex.Category(femaleId).label,
data: this.Data({sex: femaleId}, false),
borderColor:"rgb(139, 0, 0)",
lineTension: 0,
fill: false,
pointRadius: 0
}
]
},
options: {
title: {
display: true,
fontSize: 20,
text: "Unemployment by sex in the UK till " + time[time.length-1]
},
legend: {
display: false,
},
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}],
xAxes: [{
display: false
}]
}
}
})
;
}
);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment