Unable to load json and csv files in d3.js

Asked 2 months ago, Updated 2 months ago, 1 views

Currently, I am thinking of implementing the force model using d3.js and implementing sources from various sites in a local environment, but both chrome and IE are stuck in cross-domain constraints and cannot load external files.

To whom I am referring: http://dataisfun.org/2014/05/20/?p=299

If you try to implement this site's source as it is, Chrome will use

1. XMLHttpRequest cannot load file://C:/Users/ryouta/Desktop/sample/timeseries.csv. Cross origin requests are only supported for protocol schemes: http, data, chrome-extension, https, chrome-extension-resource/

2. Uncaught TypeError: Cannot read property 'length' of null

This error is displayed and IE displays Access Denied and cannot read.
I've looked at a lot of things and started up a cmd after a Google Chrome link with administrator privileges -- try allow-file-access-from-files and add .json in MIME, but I can't help it.
Implemented using HTML and Javascript.
Please help me.

javascript d3.js

2022-09-30 14:22

1 Answers

I will skip the detailed explanation, but XMLHttpRequest (which d3.js should be using) is limited for security reasons.

The solution is to use a browser that allows you to access the URL of another file scheme from HTML of the file scheme (I think Firefox has been created), but
It's the easiest place to start a server locally during development, and then test it there.

I use Browsersync and Python 3's http.server module.


2022-09-30 14:22

If you have any answers or tips


© 2022 OneMinuteCode. All rights reserved.