How to set up project to use D3

I am attempting to do my first D3 certification project. When I attempt to do anything with D3, my page does not respond. I made a simple index.html file with the script tags inside the body. I used npm init
npm i
npm i d3

after seeing nothing happening in my browser. I also tried to make sure the content was loaded with the function they provide in the AJAX section. I am sure it is a very simple thing I am messing up right now, but I can’t get past it. Here is my index.html code so far

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Gross Domestic Product</title>

        <script>"body").append("h1").text("Learning D3");

        <!-- <h1>hello world</h1>
        <button id="test">Test Button</button> -->

    <!-- <script src="script.js" type="javascript/text"></> -->

When you are not making a project in Node environment, you don’t need to use NPM for the project.

As documentation said, you can add this import statement at the beginning of the script tag (Don’t forget to add type="module" attribute.):

<script type="module">

import * as d3 from "";


Now, it should work properly.

Good luck!

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.