Created
June 1, 2020 03:54
-
-
Save pg1647/728d044ec34d669b4917386e2ef4a65c to your computer and use it in GitHub Desktop.
Data Vis. Summer 2020 || Lab 1- Task 5 // source https://jsbin.com/bavezac
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> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>DV1 - Lab : Task 4</title> | |
<script src="https://raw.githack.com/hvo/datasets/master/us-refugees.js | |
" type="text/javascript"> | |
</script> | |
<style id="jsbin-css"> | |
.bar { | |
fill: SteelBlue; | |
stroke: White; | |
} | |
#title { | |
stroke: Cyan; | |
fill: blue; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="chart"></div> | |
<script id="jsbin-javascript"> | |
var count =[ | |
refugees[0]['Year'], | |
Object.entries(refugees[0]) | |
.filter(item => (item[0]!='Year')) | |
.reduce((total, item) => (total+item[1]), 0) | |
]; | |
console.log(count); | |
var counts = refugees.map(obj => ([ | |
obj['Year'], | |
Object.entries(obj) | |
.filter(item => (item[0]!= 'Year')) | |
.reduce((total, item) => (total+item[1]), 0) | |
])); | |
console.log(counts); | |
function addElementSVG(parent, name, attrs={}) { | |
const SVGNS = "http://www.w3.org/2000/svg"; | |
let element = document.createElementNS(SVGNS, name); | |
for (let key in attrs) | |
element.setAttributeNS(null, key, attrs[key]); | |
parent.appendChild(element); | |
return element; | |
} | |
var maxValue = Math.max(...counts.map(d => d[1])); | |
// a(...[1,2,3]) -> a(1,2,3) | |
var chart = document.getElementById('chart'); | |
var svg = addElementSVG(chart, 'svg', { | |
'width': 300, | |
'height': 800, | |
}); | |
counts.forEach((d, i) => { | |
addElementSVG(svg, "rect", { | |
"class": "bar", | |
"x": 60, | |
"y": 50 + i*17, | |
"width": d[1]/maxValue*200, | |
"height": 16, | |
}); | |
addElementSVG(svg, "text", { | |
"x": 20, | |
"y": 65 + i*17, | |
}).textContent = d[0]; | |
}); | |
addElementSVG(svg, "text", { | |
"x": 20, | |
"y": 20, | |
}).textContent = "Total Number of Refugees"; | |
</script> | |
<script id="jsbin-source-css" type="text/css">.bar { | |
fill: SteelBlue; | |
stroke: White; | |
} | |
#title { | |
stroke: Cyan; | |
fill: blue; | |
}</script> | |
<script id="jsbin-source-javascript" type="text/javascript">var count =[ | |
refugees[0]['Year'], | |
Object.entries(refugees[0]) | |
.filter(item => (item[0]!='Year')) | |
.reduce((total, item) => (total+item[1]), 0) | |
]; | |
console.log(count); | |
var counts = refugees.map(obj => ([ | |
obj['Year'], | |
Object.entries(obj) | |
.filter(item => (item[0]!= 'Year')) | |
.reduce((total, item) => (total+item[1]), 0) | |
])); | |
console.log(counts); | |
function addElementSVG(parent, name, attrs={}) { | |
const SVGNS = "http://www.w3.org/2000/svg"; | |
let element = document.createElementNS(SVGNS, name); | |
for (let key in attrs) | |
element.setAttributeNS(null, key, attrs[key]); | |
parent.appendChild(element); | |
return element; | |
} | |
var maxValue = Math.max(...counts.map(d => d[1])); | |
// a(...[1,2,3]) -> a(1,2,3) | |
var chart = document.getElementById('chart'); | |
var svg = addElementSVG(chart, 'svg', { | |
'width': 300, | |
'height': 800, | |
}); | |
counts.forEach((d, i) => { | |
addElementSVG(svg, "rect", { | |
"class": "bar", | |
"x": 60, | |
"y": 50 + i*17, | |
"width": d[1]/maxValue*200, | |
"height": 16, | |
}); | |
addElementSVG(svg, "text", { | |
"x": 20, | |
"y": 65 + i*17, | |
}).textContent = d[0]; | |
}); | |
addElementSVG(svg, "text", { | |
"x": 20, | |
"y": 20, | |
}).textContent = "Total Number of Refugees";</script></body> | |
</html> |
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
.bar { | |
fill: SteelBlue; | |
stroke: White; | |
} | |
#title { | |
stroke: Cyan; | |
fill: blue; | |
} |
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
var count =[ | |
refugees[0]['Year'], | |
Object.entries(refugees[0]) | |
.filter(item => (item[0]!='Year')) | |
.reduce((total, item) => (total+item[1]), 0) | |
]; | |
console.log(count); | |
var counts = refugees.map(obj => ([ | |
obj['Year'], | |
Object.entries(obj) | |
.filter(item => (item[0]!= 'Year')) | |
.reduce((total, item) => (total+item[1]), 0) | |
])); | |
console.log(counts); | |
function addElementSVG(parent, name, attrs={}) { | |
const SVGNS = "http://www.w3.org/2000/svg"; | |
let element = document.createElementNS(SVGNS, name); | |
for (let key in attrs) | |
element.setAttributeNS(null, key, attrs[key]); | |
parent.appendChild(element); | |
return element; | |
} | |
var maxValue = Math.max(...counts.map(d => d[1])); | |
// a(...[1,2,3]) -> a(1,2,3) | |
var chart = document.getElementById('chart'); | |
var svg = addElementSVG(chart, 'svg', { | |
'width': 300, | |
'height': 800, | |
}); | |
counts.forEach((d, i) => { | |
addElementSVG(svg, "rect", { | |
"class": "bar", | |
"x": 60, | |
"y": 50 + i*17, | |
"width": d[1]/maxValue*200, | |
"height": 16, | |
}); | |
addElementSVG(svg, "text", { | |
"x": 20, | |
"y": 65 + i*17, | |
}).textContent = d[0]; | |
}); | |
addElementSVG(svg, "text", { | |
"x": 20, | |
"y": 20, | |
}).textContent = "Total Number of Refugees"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment