【发布时间】:2020-09-06 20:44:13
【问题描述】:
d3.csv(...).then 不是函数
app.js
// Select body, append SVG area to it, and set the dimensions
var svg = d3.select("body")
.append("svg")
.attr("height", svgHeight)
.attr("width", svgWidth);
// Append a group to the SVG area and shift ('translate') it to the right and to the bottom
var chartGroup = svg.append("g")
.attr("transform", `translate(${chartMargin.left}, ${chartMargin.top})`);
// Load data from hours-of-tv-watched.csv
d3.csv("hours-of-tv-watched.csv").then(function(tvData) {
console.log(tvData);
// Cast the hours value to a number for each piece of tvData
tvData.forEach(function(d) {
d.hours = +d.hours;
});
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<title>Hours of TV Watched Each Month</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<script src="app.js"></script>
</body>
</html>
CSV:
name,hours
Han,33
Christian,12
Lisa,41
Jacob,16
Nick,59
Ahmed,38
Peleke,21
Matt,25
我正在使用app.js,显示错误:
d3.csv(...).then 不是函数
我使用的是最新的 D3 版本。我尝试过使用不同的格式:
<script src="http://d3js.org/d3.v3.min.js">
但没用。
【问题讨论】:
-
嗨,Mehdi,我已尝试搜索其他答案,但您向我展示的答案无效。
标签: javascript html csv d3.js