简体   繁体   中英

svg element not appearing in the body using d3.js

I am following a tutorial and I am trying to create an svg element using d3. however when I run it and inspect the page on chrome, the svg element isnt showing up in the body. I'm sure that the .html file is referencing the correct js file, but I cant figure out why the element isn't appending

this is my html code

    <!DOCTYPE html>
    <html lang="en">
        <head>
            <meta charset="utf-8">
            <title>example</title>
            <link rel="stylesheet" type="text/css" href="style.css">
            <script type="/text/javascript" src="d3.v3.min.js">
            </script>

        </head>
        <body>
            <script type="/text/javascript" src="shapes.js"></script>

        </body>
    </html>

and this is my js code

    var dataArray = [2,13,15];
    d3.select("body").append("svg");

It's your type attributes on your script tags:

/text/javascript

is not valid, it's:

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

With no leading slash...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM