Data Recovery for D3.js Challenge "Visualize Data with a Bar Chart"

Hello everybody,
Facing the challenge “Visualize Data with a Bar Chart” of the curriculum I tried to retrieve the data with the fetch and with the json method of d3, with the latter you do not receive an answer and with fetch the request remains pending but with a fulfilled status, can you tell me why and how to solve it?

I am attaching the link to the project on codepen

Link: https://codepen.io/maurizio8788/pen/xxqjxWB?editors=0010

and the console screen to help you … thank you very much everyone!

Hello there,

Your getAllData is, as defined by you, an asynchronous function. Therefore, to make use of what it returns, you need to await its response.

You are not awaiting its response here:

let dataset = getAllData(url);

Hope this helps

1 Like

Hi and thank you very much for the answer, but if I put await in that variable it gives me an error, could you tell me why?

I did it like this:

let dataset = await getAllData(url);

Sure.

It does not make sense (from a JS runtime perspective) to call await outside of an async function. So, you need to have any await within an async function…

This is why libraries like d3 and jQuery come with methods like onReady, and wrap all of the logic.

Hint for what to do:

You need to wrap all of your data fetching/using logic within an async function

Hope this clarifies

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.