d3.js - d3 JS 版本 6 d3.v6.min.js:2 Uncaught (in promise) TypeError
问题描述
我正在使用最新版本 6 学习 D3 JS。我正在尝试从外部文件中获取 CSV 数据,如果使用 D3 JS 版本 4,它运行良好,但使用最新版本时会出现错误。
d3.v6.min.js:2 Uncaught (in promise) TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))
at Function.from (<anonymous>)
at sb (d3.v6.min.js:2)
at a (d3.v6.min.js:2)
at working_with_csv_1.html:41
at d3.v6.min.js:2
at d3.v6.min.js:2
at r (d3.v6.min.js:2)
at parse (d3.v6.min.js:2)
at d3.v6.min.js:2
我的代码是:
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>D3 SVG LINE CHART</title>
<style>
</style>
<script src="https://d3js.org/d3.v6.min.js"></script>
<script src="https://d3js.org/d3-selection-multi.v0.4.min.js"></script>
</head>
<body>
<h3>CSV in D3JS</h3>
<script>
var w = 400;
var h = 100;
var ds; //global dataset
d3.csv('MonthlySales.csv',
d3.autoType, function(error, data){
if(error)
console.log(error);
else {
console.log(data);
ds = data;
}
var linFunc = d3.line()
.x(function(d){ return ((d.month-20130001)/3.25)})
.y(function(d) { return h-d.sales})
.curve(d3.curveNatural);
var svg = d3.select("body").append("svg")
.attrs({
width: w,
height: h
});
var viz = svg.append("path")
.attrs({
d: linFunc(ds),
"stroke": "red",
"stroke-width": 2,
"fill": "none"
});
});
</script>
</body>
</html>
我的 CSV 文件数据:[1]:https ://i.stack.imgur.com/P6ElF.png
有什么线索我可以解决这个问题吗?我使用的是不稳定版本的 DS JS 吗?请指导!
解决方案
推荐阅读
- cassandra - 压缩 - TimeWindowCompactionStrategy Cassandra 3
- scala - 如何更改 StructType 的 StructField 中列的数据类型?
- javascript - 不明白我的“不必要的转义字符”错误来自哪里
- angular - 给定日期一年中的周数
- sql - 带有大小写检查空值的 SQL Server Where 子句
- oracle - 显示表空间详细信息的 Oracle 过程
- java - 将包含非 ASCII 字符的参数从 bash 传递到 Java 程序
- c# - 如何通过输入和输出绑定连接 Azure Functions 2.0 CosmosDB?
- c - 我对 PIC16F54 的这段代码做错了什么?
- node.js - Mongoose isDeleted 类型干扰