简体   繁体   English

d3:如何将外部CSV文件加载到数据中?

[英]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. 我正在尝试学习如何将外部数据(在我的计算机中)加载到d3代码中。

However, I can't load data just as the tutorial do d3.csv("data.csv", type, function(error, data) . 但是,我不能像教程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. 我尝试附加d3.csv("users/file/data.csv")类的URL,但无法正常工作。

Please let me know how to load the CSV file that is located in my computer. 请让我知道如何加载计算机中的CSV文件。

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. 诀窍在于,您的浏览器需要能够使用您提供的URL访问文件,因此,如果将d3代码托管在网络服务器上,则还必须托管data.csv。

If you use a relative path, then the path is relative to your HTML file. 如果使用相对路径,则该路径是相对于HTML文件的。

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. 但请确保data.csv与用于HTML的HTML文件位于同一位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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