D3 如何进一步传递 Promise.all 数据?
D3 how to pass Promise.all data further?
你能看看吗?没有出现地图
https://codepen.io/DeanWinchester88/pen/BaZYewv
async function chart() {
const [data,geo] = await Promise.all([
d3.json(promises[0]),
d3.json(promises[1])
])
console.log("data",data)
console.log("geo", geo)
}
chart()
let path = d3.geoPath()
function ready(error,data,geo){
//topojson object
let topoobject = topojson.feature(geo, geo.objects.counties);
let counties = topoobject.features;
您需要将数据传递给ready
函数。现在在您的代码中,永远不会调用 ready
函数。你可以这样做:
Promise.all([
d3.json(EDUCATION),
d3.json(COUNTIES),
]).then(([data, geo]) => {
ready(null, data, geo);
});
另外,EDUCATION
url中有一个错误。应该是:
const EDUCATION = "https://cdn.freecodecamp.org/testable-projects-fcc/data/choropleth_map/for_user_education.json";
const COUNTIES = "https://cdn.freecodecamp.org/testable-projects-fcc/data/choropleth_map/counties.json";
最后,ready
第一行拼写错误topojson
。
你能看看吗?没有出现地图
https://codepen.io/DeanWinchester88/pen/BaZYewv
async function chart() {
const [data,geo] = await Promise.all([
d3.json(promises[0]),
d3.json(promises[1])
])
console.log("data",data)
console.log("geo", geo)
}
chart()
let path = d3.geoPath()
function ready(error,data,geo){
//topojson object
let topoobject = topojson.feature(geo, geo.objects.counties);
let counties = topoobject.features;
您需要将数据传递给ready
函数。现在在您的代码中,永远不会调用 ready
函数。你可以这样做:
Promise.all([
d3.json(EDUCATION),
d3.json(COUNTIES),
]).then(([data, geo]) => {
ready(null, data, geo);
});
另外,EDUCATION
url中有一个错误。应该是:
const EDUCATION = "https://cdn.freecodecamp.org/testable-projects-fcc/data/choropleth_map/for_user_education.json";
const COUNTIES = "https://cdn.freecodecamp.org/testable-projects-fcc/data/choropleth_map/counties.json";
最后,ready
第一行拼写错误topojson
。