Skip to content

Instantly share code, notes, and snippets.

@clemsos
Last active January 27, 2018 02:07
Show Gist options
  • Select an option

  • Save clemsos/58c14a2fb231a3cdc1118d021673b518 to your computer and use it in GitHub Desktop.

Select an option

Save clemsos/58c14a2fb231a3cdc1118d021673b518 to your computer and use it in GitHub Desktop.
3GPP Organizations by countries
license: mit
{
"2018": {
"UNITED KINGDOM": 9,
"NETHERLANDS": 2,
"JAPAN": 6,
"INDIA": 3,
"FRANCE": 9,
"UNITED STATES": 12,
"SWEDEN": 2,
"CHINA": 14,
"Others": 25,
"GERMANY": 9,
"KOREA (REPUBLIC OF)": 3
},
"2013": {
"NETHERLANDS": 3,
"ITALY": 3,
"TAIWAN, PROVINCE OF CHINA": 3,
"UNITED STATES": 17,
"Others": 24,
"JAPAN": 7,
"KOREA (REPUBLIC OF)": 3,
"UNITED KINGDOM": 14,
"FRANCE": 10,
"GERMANY": 11,
"CHINA": 5
}
}
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
div { margin: 0 auto}
</style>
</head>
<body>
<div class="chart" style="width:50%; max-height : 100%">
<canvas id="chart" width="100" height="100"></canvas>
</div>
<script>
var file = "3gpp.json"
var colorScale = d3.scaleOrdinal(d3.schemeCategory20)
d3.json(file, function(data){
console.log(data)
var datasets = []
Object.keys(data["2013"])
.sort((a,b) => data["2013"][a]-data["2013"][b])
.forEach(country => datasets[country] = [data["2013"][country]])
Object.keys(data["2018"])
.sort((a,b) => data["2018"][a] - data["2018"][b])
.forEach(country =>
datasets[country] != undefined ?
datasets[country].push(data["2018"][country])
: datasets[country] = [ 0, data["2018"][country]]
)
Object.keys(datasets)
.forEach( country => datasets[country].length ==1 ? datasets[country].push(0) : null )
var final = Object.keys(datasets).map( country => ({
"label" : country,
// "yAxisID" : country,
"backgroundColor" : colorScale(country),
"borderColor" : colorScale(country),
"data" : datasets[country],
"fill" : false
}))
.sort( (a,b) => a.data[1] - b.data[1])
console.log(final)
config = {
type: 'line',
data: {
datasets: final,
labels : [2013, 2018]
},
options: {
responsive: true,
legend: {
position: 'right',
labels : {
useLineStyle: true,
}
,"display": true
,reverse : true
},
title: {
display: true,
text: 'Members of 3GPP (mobile networks standards) by countries - src : 3GPP, Qualcomm'
},
animation: {
animateScale: true,
animateRotate: true
},
scales: {
yAxes: [{
scaleLabel: {
display: true,
labelString: 'Number of organisations (% of total)'
}
}]
}
}
}
var ctx = document.getElementById("chart").getContext("2d");
window.myDoughnut = new Chart(ctx, config);
})
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment