can't run the most simple d3.js example code

2,733 views
Skip to first unread message

Joe Smith

unread,
Apr 2, 2016, 3:52:43 AM4/2/16
to d3-js

I copied and pasted the code of the following bar chart example code of d3.js into a index.html file on my computer:
https://bl.ocks.org/mbostock/7322386

However, when I double click the index.html file nothing is shown in the Chrome browser.

I used the Inspector to check the error, and I got the following message as shown in the image:

May I ask why the source of the d3.js library online cannot be accessd?

Thank you!




Nigel Legg

unread,
Apr 2, 2016, 4:05:16 AM4/2/16
to d3...@googlegroups.com
Have you downloaded d3.js? The code 
<script src="//d3js.org/d3.v3.min.js"></script>
has it on the local machine.  

Cheers, Nigel
mobile 07758 665575
skype: nigellegg

--
You received this message because you are subscribed to the Google Groups "d3-js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to d3-js+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joe Smith

unread,
Apr 2, 2016, 6:56:37 AM4/2/16
to d3-js

Thank you, Nigel!

Yes, I've download D3 and the d3.min.js and d3.js files are put in the same folder as the index.html folder.

I found if I change the following code:
<script src="//d3js.org/d3.v3.min.js"></script>
...to this code:
<script src="d3.min.js"></script>
The index.html file will work by showing the bar chart.

So, I wonder why the D3 library online can't be accessed by the web address as shown in the original code...

Hope you can advise!
Thank you!

Jean Mercier

unread,
Apr 2, 2016, 7:07:08 AM4/2/16
to d3...@googlegroups.com
Hi Joe,


Add http: (http://d3js.org/d3.v3.min.js) and it will work

Best,
Jean

Cet e-mail a été envoyé depuis un ordinateur protégé par Avast.
www.avast.com

Nigel Legg

unread,
Apr 2, 2016, 7:19:30 AM4/2/16
to d3...@googlegroups.com
Original code does not have a complete web address. 

Cheers, Nigel
mobile 07758 665575
skype: nigellegg

Joe Smith

unread,
Apr 2, 2016, 7:44:16 AM4/2/16
to d3-js
Noted with many thanks, Jean and Nigel!

It works now after adding "http:" to the src part of the code.

Ian Johnson

unread,
Apr 5, 2016, 1:35:27 PM4/5/16
to d3...@googlegroups.com
The fix you found is only a temporary solution, you will quickly run into the limitations of running d3 examples from your filesystem (you wont be able to load data using d3.json/csv etc). What you want to do is run a local server like
python -m SimpleHTTPServer

or use something like served: http://enjalot.github.io/served/
Ian Johnson - 周彦
Reply all
Reply to author
Forward
0 new messages