d3.js - D3 如何进一步传递 Promise.all 数据?
问题描述
你能看看吗?没有地图出现
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
另外,网址有误。它应该是:
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
。
推荐阅读
- angular - 在服务中实例化 RxJs 主题
- javascript - 为什么在使用 react-table 时使用 `useTable` 而不是 `ReactTable`
- perl - Perl 中的 eval gawk,如何处理引号?
- r - 将嵌套字符列表修改为 R 中的数字
- bash - Docker 容器在创建命令后停止
- python - 删除课程内容中的括号
- javascript - Sencha Ext JS 日期面板年份选择器配置
- amazon-web-services - 模拟 AWS Go SSM GetParameter 调用
- date - Elasticsearch (7.3) 日期映射解析失败
- python - GitHub 的 API 是否支持一次检索多个用户的元数据?