🏠 back to Observable

Listening to progress events in d3.csv()


Is there a way to listen to progress events in d3.csv() v5? I’d like to do something like this: https://bl.ocks.org/mbostock/3750941/d23bee17cef9a0e4d219bc6b47b59a72b50767dd

but it seems since d3@5 we can’t do this anymore.


Yes, the Fetch API supports streaming:

It’s not a drop-in replacement for progress events, because the Fetch API is quite different from the old XMLHttpRequest. But you could use the technique above to monitor the progress of the download, and then when it’s downloaded entirely, parse the CSV using d3.csvParse.

There must be some streaming CSV parsers around. I implemented one myself at some point, but not in a way that’s compatible with the newer Streams API. It might be nice to revisit that now that browsers support it.