我想用 for 循环创建下面的数组作为它的大
var centres = {
1979: { x: width * 1 / 41, y: height / 2 },
1980: { x: width * 2 / 41, y: height / 2 },
1981: { x: width * 3 / 41, y: height / 2 },
...
}
然后按如下方式访问它:
function nodeYearPos(d) {
return yearCenters[d.year].x;
}
我有以下代码,但它只设置年份......
var yearCenters = Array.from(new Array(2020-1919+1), (x, i) => i + 1919);
for (year = 1919; year <= 2020; year++) {
coords = getCentres(year); // this returns an object in the form {x : x, y : y}
yearCenters[year] = coords;
}
慕神8447489
繁花如伊
相关分类