D3 Bar Graph example not working locally

前端 未结 3 1053
灰色年华
灰色年华 2020-11-27 21:09

I am very new to D3, and wanted to see how an example would work locally. I copied and pasted the bar graph code to a local file called index.html, and also copied over the

3条回答
  •  萌比男神i
    2020-11-27 21:48

    The d3.tsv method makes an AJAX request for data. On most browsers, this won't work locally due to the Same Origin Policy, which generally prohibits AJAX requests to file:/// urls.

    To get an example that uses AJAX running locally, you'll need a local webserver. If you have Python, running

    > python -m SimpleHTTPServer
    

    from the command line in the directory with your files will do it.

    and if you are using python 3

    > python -m http.server 9000
    

    If you prefer node.js, try http-server.

提交回复
热议问题