简体   繁体   中英

d3: how can I load external CSV file into data?

I am trying to learn how to load external data (in my computer) into d3 code.

However, I can't load data just as the tutorial do d3.csv("data.csv", type, function(error, data) .

I tried to attach the URL like d3.csv("users/file/data.csv") but it didn't work.

Please let me know how to load the CSV file that is located in my computer.

The trick is that your browser needs to be able to access the file using the URL that you provide, so if you host your d3 code on a web server, then you have to host the data.csv as well.

If you use a relative path, then the path is relative to your HTML file.

Try using

d3.csv("data.csv", type, function(error, data)]

but make sure that data.csv is in the same location as the HTML file that you are using for your HTML.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM