import d3 in .js file

484 views
Skip to first unread message

Ankit Dwivedi

unread,
Feb 27, 2023, 5:27:40 AM2/27/23
to d3-js
Hello All,

I am trying to use d3 in my one of the project and want to import d3 in another js file.
I have used the syntax as mentioned below but it is giving error "Cannot use import statement outside a module".
import * as d3 from "/.d3.min.js";

Could anyone have any idea how to import it correctly ?




Regards
Ankit Dwivedi


Curran

unread,
Feb 28, 2023, 12:26:52 AM2/28/23
to d3-js
Greetings Ankit,

If you are not using any build tools, the easiest way to get D3 into your page is to load it from a CDN site like this:

<!DOCTYPE html>
<html>
  <head>
    <title>D3 Starter</title>
    <script src="https://unpkg.com/d...@7.6.1/dist/d3.min.js"></script>
  </head>
  <body></body>
  <script src="your-javascript-file.js"></script>
</html>

Then you can refer to the global variable d3 in your JS.

You may like these courses for learning: https://vizhub.com/forum/t/index-of-courses/289

Best regards,
Curran

Reply all
Reply to author
Forward
0 new messages