Published
Edited
Jul 11, 2020
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
parsedData = []
Insert cell
data = {
const text = await FileAttachment("combined_happiness_dataset@3.csv").text();
const data = d3.csvParse(text, function(d){
return ({
country: d.Country,
region: d.Region,
2015: +d['2015'],
2016: +d['2016'],
2017: +d['2017'],
2018: +d['2018'],
2019: +d['2019'],
2020: +d['2020']});
});
return data;
}
Insert cell
process_parsedData = function() {
data.forEach((d) => {
var dObj = {
country: d.country,
ranks: []
};
for (var year in d) {
if (year != "country" & year != "region") {
if (d[year] != 0) {
dObj.ranks.push({
year: +year,
rank: +d[year],
country: dObj
});
}
}
}
parsedData.push(dObj);
});
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
margin = ({
top: 50,
right: 200,
bottom: 100,
left: 125
});
Insert cell
d3 = require("d3@4")
Insert cell
width = 1200 - margin.left - margin.right;
Insert cell
height = 2200 - margin.top - margin.bottom;
Insert cell
colorScale = d3.scaleLinear().domain([1,139]).range(d3.interpolateCool)
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more