我知道這是個超級簡單的問題。但我顯然錯過了一些超級明顯的東西。
我只是想用D3創建一個svg元素并在我的頁面上看到它。
我的index.html是這樣的:
<!DOCTYPEhtml>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" >
<meta name="viewport" content="width=device-width, initial-scale=1.0" >
<script src="node_modules/d3/dist/d3.min.js"></script>
<腳本 src="selections.js"></script>
<link rel="styleheet" href="style.css">
<title>D3選擇</title>
</head>
<body>
</body>
</html>
而我的selections.js則是這樣的:
console.log("this appears..." )
w = window.innerWidth。
h = window.innerHeight。
//make the svg。
const svg = d3.select("body"/span>)
.append("svg")
.attr("高度", h)
.attr("width", w)
.attr("class", "spvg")
第一個console.log()在控制臺仍然可見。但是我看不到svg。我知道我錯過了一些超級清晰的東西,但我現在就是看不到它:/
uj5u.com熱心網友回復:
我對d3.js不是很了解,但你可能應該等待DOM的加載:
console.log("this appears...") 。
w = window.innerWidth。
h = window.innerHeight。
document.addEventListener('DOMContentLoaded', e => /span>{
// make the svg
const svg = d3.select("body"/span>)
.append("svg")
.attr("height", h)
.attr("width", w)
.attr("class", "svg") 。
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/320656.html
標籤:
