2 回答

TA貢獻1765條經驗 獲得超5個贊
假設您的 company.csv 類似
X、Y、半徑
100,20,10
150,80,10
<!DOCTYPE HTML>
<HTML>
<head>
<meta charset="utf-8" />
<title>companies</title>
<style>
.svg {
background-color: gray;
height: 400px;
width: 800px;
}
</style>
<script src="https://d3js.org/d3.v5.min.js"></script>
</head>
<body>
<svg class='svg'></svg>
<script>
d3.csv('./company.csv', function (the_data) {
console.log("X", the_data.X)
console.log("radius", the_data.radius)
build_viz(the_data);
});
function build_viz(the_data) {
d3.select('.svg')
.append("circle")
.attr("cx", the_data.X)
.attr("cy", the_data.Y)
.attr("r", the_data.radius)
.attr('fill', 'red')
}
</script>
</body>
輸出:

TA貢獻1786條經驗 獲得超11個贊
svg
頁面主體中沒有元素。
結果,d3.select("svg")
返回一個空選擇,因此圓圈不會附加到任何內容。
通過在腳本之前添加以下內容來修復<body>
:
<svg width="800px" height="400px"></svg>
- 2 回答
- 0 關注
- 185 瀏覽
添加回答
舉報