Why is code to retrieve data not working if it has worked in a different project?

My code to retrieve the dataset for the scatter plot:
d3.json('url', function(data) { ... }
does not seem to be working because when I console.log(data) nothing appears in the console

What could be wrong? (I’ve used this code for my bar chart project and it worked fine there)

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36

Challenge: Visualize Data with a Scatterplot Graph

Link to the challenge:

Hey @jaimeggb ,

It has got to do with the d3 version which you are using.

With the version you’re using ( 7.0), you could try d3.json(url).then(callback fn(data)) as d3.json is an asynchronous function and returns a promise. ← basically wrapping the callback fn inside .then()

For the code which you’ve written, just changing the d3 version to something older like ‘https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.2/d3.min.js’ would work.

Hope this helps.

1 Like

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