我第一次使用 d3.nest() 函数试图在 d3 中绘制一个等值线。现在,当我嵌套年份和国家/地区时,我看到国家(如 $AUS)和年份(如 1960 美元)都附加了“$”符号。那么,是否需要将数组作为 dataByCountryAndyear['$AUS'] 访问?
似乎在 d3 v4 中预期该行为,但是我想了解在这种情况下使用键访问对象的正确方法是什么。
function ready(error, country_data, lfpr_data) {
// converting strings to numbers where necessary
lfpr_data.forEach(d => {
d.year = +d.year
d.female_lfpr = +d.female_lfpr;
d.male_lfpr = +d.male_lfpr;
});
// nesting by country and year i.e for each country all years beneath it
var dataByCountryByYear = d3.nest()
.key(function(d) { return d.country; })
.key(function(d) { return d.year; })
.map(lfpr_data);
console.log(dataByCountryByYear['$AUS'])
country_data.features.forEach(each_country => {
each_country.properties.years = dataByCountryByYear[each_country.id]
});
}
我的数据如下所示:
year country country_name region female_lfpr male_lfpr total_lfpr
1960 ABW Aruba Latin America & Caribbean NA NA NA
1960 AFG Afghanistan South Asia NA NA NA
1960 AGO Angola Sub-Saharan Africa NA NA NA
1960 ALB Albania Europe & Central Asia NA NA NA
1960 AND Andorra Europe & Central Asia NA NA NA
1960 ARE United Arab Emirates Middle East & North Africa NA NA NA
1960 ARG Argentina Latin America & Caribbean NA NA NA
1960 ARM Armenia Europe & Central Asia NA NA NA
1960 ASM American Samoa East Asia & Pacific NA NA NA
1960 ATG Antigua and Barbuda Latin America & Caribbean NA NA NA
相关分类