- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我发现列出了几个此类性质的问题。所以我有同样的问题:D3 - 未捕获类型错误:无法读取未定义的属性“长度”。
这发生在第 42 行: d: lineFun(ds.monthlySales)
感激不尽的任何想法,
谢谢杰瑞
我的代码和json如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>fm</title>
<script src="d3.min.js"></script>
<link rel="stylesheet" href="FMstyle.css" />
</head>
<body>
<div class="pageHeading">Facilities Management</div><br />
<script>
var h=100;
var w=400;
var ds; // global dataset variable
var salesTotal;
var salesAvg;
var metrics=[];
//function showHeader() {
// d3.select("#tree-container").append("h1")
// .text(ds.cat)
//}
function buildLine() {
var lineFun = d3.svg.line()
.x(function (d) { return d.month; })
.y(function (d) { return h-d.sales; })
.interpolate("linear");
var svg = d3.select("#tree-container").append("svg")
.attr({ width: w, height: h });
var viz = svg.append("path").attr({
d: lineFun(ds.monthlySales),
"stroke": "purple",
"stroke-width": 2,
"fill": "none"
});
}
d3.json("sales.json", function(error, data) {
if(error) {
console.log(error);
} else {
console.log("found some data");
console.log(data);
ds=data;
}
buildLine();
});
</script>
<div id="tree-container"
style="border: solid 1px blue; float: left;"></div>
<div style="border: solid 1px blue; width: 20%;
float: left; margin-left: 5px;">
<p>Properties</p>
<p>Properties</p>
<p>Properties</p>
</div>
</body>
</html>
[{ "content": [
{
"category": "Furniture",
"region": "West",
"monthlySales":
[{
"month":1,
"sales":38
},
{
"month":2,
"sales":40
},
{
"month":3,
"sales":41
},
{
"month":4,
"sales":39
},
{
"month":5,
"sales":43
},
{
"month":6,
"sales":35
}]
}]
}
]
最佳答案
JSON 的结构与您想要执行的操作不匹配。 lineFun
需要一个数组但没有得到一个。轻松修复!
而不是:
ds=data;
用途:
ds=data[0].content[0].monthlySales;
这是一个有效的方法: http://plnkr.co/edit/Q9lfkY2Vc6g0rYYIAUKm?p=preview
如果您在浏览器中使用检查器,您可以看到生成的路径如下所示:
<path d="M1,62L2,60L3,59L4,61L5,57L6,65" stroke="purple" stroke-width="2" fill="none"></path>
但是路真的很短!
您可能想使用 d3.scale.linear 来标准化数据:
关于javascript - D3 JS - 未捕获类型错误 : Cannot read property 'length' of undefined - seems related to data issue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27784895/
我找到了以下代码片段: length = length and length or len(string) 在我看来,这应该等同于: length = length or len(string) 我能
当我使用 numpy.shape() 检查数组的形状时,我有时会得到 (length,1) 有时会得到 (length,)。看起来区别在于列向量与行向量......但它似乎并没有改变数组本身的任何内容
我正在学习 Java,有一个简单的问题。 在设置类的示例中,我看到了这一点: length >= 0 ? length : length * -1 这是什么意思? 谢谢。 最佳答案 这是一种骇人听闻的
我在阅读有关在 Ruby 中重新定义方法有多么容易的文章时遇到了以下问题: class Array alias :old_length :length def length old_l
例如在下面的代码中a和b和c是相等的。 EditText editText; editText = (EditText) findViewById(R.id.edttxt); editText.set
在昨天教授我的 JavaScript 类(class)时,我和我的学生遇到了一些有趣的功能,我认为这些功能可能值得在一个问题和我得出的答案中捕捉到。 在 Chrome 的 JS 控制台中输入 Arra
这个问题在这里已经有了答案: How can I get the size of an array, a Collection, or a String in Java? (3 个回答) 3年前关闭。
这个问题在这里已经有了答案: length and length() in Java (8 个答案) 关闭 6 年前。 我注意到在计算数组的长度时,你会这样写: arrayone.length; 但
console.log(this.slides.length()); 打印 Cannot read property 'length' of undefined.在 setTimeout 为 100
在搜索stackoverflow问题时,我发现了此链接: Error in file.download when downloading custom file。 但是,我的情况有些不同(我认为):
这个问题已经有答案了: Why does R use partial matching? (1 个回答) 已关闭 8 年前。 大家。我刚刚开始使用 swirl 学习 R 编程。 我刚刚了解到seq 。
这个问题已经有答案了: Why does R use partial matching? (1 个回答) 已关闭 8 年前。 大家。我刚刚开始使用 swirl 学习 R 编程。 我刚刚了解到seq 。
这个问题已经有答案了: How can I get the size of an array, a Collection, or a String in Java? (3 个回答) 已关闭 9 年前。
我有一个大数组,其中包含所有类型( bool 值,数组,null,...),并且我正在尝试访问它们的属性arr[i].length,但有些其中显然没有长度。 我不介意那些缺少长度的人是否返回未定义(我
我在对象的属性中有一些文本。我正在测试对象的属性中是否有要显示的文本;如果没有,那么我显示“-”而不是空白。看起来没有什么区别: if (MyObject.SomeText && MyObject.S
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: Why is String.length() a method? Java - Array's length
这个问题在这里已经有了答案: obj.length === +obj.length in javascript (4 个答案) 关闭 9 年前。 我一直在读underscore.js源代码并在 _.
#include using std::cout; using std::cin; using std::string; int main(){ cout > name; cout
我正在细读 underscore.js annotated source当我遇到这个时: if (obj.length === +obj.length) {...} 我现在从this stackove
我正在查看 dotnet 运行时中的一些代码,我注意到不是这样写的: if (args.Length > 0) 他们使用这个: if (args is { Length: > 0}) 你知道用第二种方
我是一名优秀的程序员,十分优秀!