Home > Mobile >  D3 how to pass Promise.all data further?
D3 how to pass Promise.all data further?

Time:09-22

Could u have a look? no map appeared

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;
  

CodePudding user response:

You need to pass the data to the ready function. Right now in your code, the ready function is never called. You can do it like this:

Promise.all([
  d3.json(EDUCATION),
  d3.json(COUNTIES),
]).then(([data, geo]) => {
  ready(null, data, geo);
});

Also, there is a mistake in the EDUCATION url. It should be:

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";

Lastly, the first line of ready misspells topojson.

  • Related