ReferenceError: d3 is not defined

6,345 views
Skip to first unread message

Tiffany Montgomery

unread,
Jan 14, 2016, 12:04:42 PM1/14/16
to d3-js
Hello everyone. I am using Cloud9 to try to load a text file with d3 using the following code:
<!DOCTYPE html>
<html>
    <head>
        <meta charset = "utf-8">
        <script src="//d3js.org/d3.v3.min.js" charset="utf-8"></script>
        <script>
            var data = d3.txt("ex1/ex1data1.txt");
        </script>
    </head>
    <body>

    </body>
</html>

The terminal is giving me this error:
                                                                                                                                      
ReferenceError: d3 is not defined                                                                                                     
    at Object.<anonymous> (/home/ubuntu/workspace/linear-regression.js:3:12)                                                          
    at Module._compile (module.js:435:26)                                                                                             
    at Object.Module._extensions..js (module.js:442:10)                                                                               
    at Module.load (module.js:356:32)                                                                                                 
    at Function.Module._load (module.js:311:12)                                                                                       
    at Module.runMain [as _onTimeout] (module.js:467:10)                                                                              
    at Timer.listOnTimeout (timers.js:92:15)    

Any suggestions?

Artur O

unread,
Jan 14, 2016, 4:29:09 PM1/14/16
to d3...@googlegroups.com

--
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.

Artur O

unread,
Jan 14, 2016, 4:32:19 PM1/14/16
to d3...@googlegroups.com
But there is no d3.txt method, there is d3.text

Mike Bostock

unread,
Jan 14, 2016, 4:41:24 PM1/14/16
to d3...@googlegroups.com
It sounds like you’re trying to run this example out of your local file system, which is breaking the protocol-less src of your script tag.

You can fix the immediate problem by adding “http:” or “https:”, like so:

<script src="https://d3js.org/d3.v3.min.js" charset="utf-8"></script>

But, you’ll then immediately run into browser security issues trying to load a file (d3.text) whilst running out of the local file system. See these instructions:


Mike
Reply all
Reply to author
Forward
0 new messages