Skip to content
Advertisement

How can I make rects from JSON?

I’m doing a project to learn d3 visualization and I’m stack recs aren’t appearing. Could you help me?

I tried to put a simple array for data and it worked, I could only flip y, but with this JSON data. nothing works

https://codepen.io/DeanWinchester88/pen/XWgjjeW

JavaScript

Advertisement

Answer

The issue is that XMLHttpRequest is asynchronous and you are defining the d3 logic outside of the callback passed to readTextFile. The easiest solution would be to include the d3 logic inside of the callback:

JavaScript

To avoid callback you could wrap the response to readTextFile in a Promise and then use async/await to dataSet = await readTextFile(...).

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement