Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

D3.js loading local data file from file:///

Tags:

d3.js

I know that D3.js supports loading data files with XHR and JSONP requests.

However in my case, I am going to run .html files by double clicking on them from filesystem, which is going to run it like file://.../foo.html on browser.

Is it possible to load data file (csv or json) within the same directory from computer as foo.html on browser (while not running on http:// but file://)?

like image 454
ahmet alp balkan Avatar asked Mar 14 '13 18:03

ahmet alp balkan


People also ask

Is D3 js still popular?

The JavaScript ecosystem has completely changed during this time, in terms of libraries, best practices and even language features. Nevertheless, D3 is still here. And it's more popular than ever.

What is better than D3 JS?

We have compiled a list of solutions that reviewers voted as the best overall alternatives and competitors to D3js, including Syncfusion Essential Studio Enterprise Edition, Chart. Js, Angular, and DevExpress.

What does D3 CSV return?

d3. csv() returns the data as an object. This object is an array of objects loaded from your csv file where each object represents one row of your csv file.

Is the syntax to read JSON data in D3?

Syntax: d3. json(input[, init]);


2 Answers

The best solution would be to run a server on your computer to make it work.

The simplest way to have a local web server, as explained here is to run this command in the directory where you have your source code:

python -m SimpleHTTPServer 8888 &

Then just load the page http://localhost:8888

like image 51
Christopher Chiche Avatar answered Oct 15 '22 19:10

Christopher Chiche


You can by disabling the respective security mechanisms in your browser. I think it works in Opera by default, and you can start Chrome with the --allow-file-access-from-files command line flag to allow loading data from file://.

like image 28
Lars Kotthoff Avatar answered Oct 15 '22 19:10

Lars Kotthoff