javascript d3 布局未定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8652163/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
d3 layout is undefined
提问by quantumpotato
Trying to use d3.jsand not sure how to reference it properly:
尝试使用d3.js但不确定如何正确引用它:
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="bootstrap.min.css">
<script src="jquery-1.7.1.js"></script>
<<<<other scripts>>>
<script src="topbar.js"></script>
<script>
$(function() {
var n = 4, // number of layers
m = 64, // number of samples per layer
data = d3.layout.stack()(stream_layers(n, m, .1)),
color = d3.interpolateRgb("#aad", "#556");
});
</script>
</head>
...
</html>
回答by mbostock
You need to include d3.layout.js in addition to d3.js; the layout module is in a separate file by default. You can also make a custom build of d3.js that includes everything you need in a single file.
除了 d3.js 之外,您还需要包含 d3.layout.js;默认情况下,布局模块位于单独的文件中。您还可以创建 d3.js 的自定义构建,在单个文件中包含您需要的所有内容。
回答by Tweak3r
You should use d3.stackinstead.
你应该使用d3.stack代替。
Every symbol in D3 4.0 now shares a flat namespace rather than the nested one of D3 3.x. For example, d3.scale.linearis now d3.scaleLinear, and d3.layout.treemapis now d3.treemap.
D3 4.0 中的每个符号现在共享一个平面命名空间,而不是 D3 3.x 的嵌套命名空间。例如,d3.scale.linear现在是d3.scaleLinear,d3.layout.treemap现在是d3.treemap。
For other d3.layout changes go here: https://github.com/d3/d3/blob/master/CHANGES.md
对于其他 d3.layout 更改,请访问:https: //github.com/d3/d3/blob/master/CHANGES.md
回答by gfjr
(it's not the answer for this question)
(这不是这个问题的答案)
For the people with the same error:
对于有同样错误的人:
d3.layout is undefined
d3.layout 未定义
In my case was the problem I just link directly to the latest release (v4)
https://d3js.org/d3.v4.min.js
就我而言,问题是我只是直接链接到最新版本 (v4)
https://d3js.org/d3.v4.min.js
With (v3) it is working again.
https://d3js.org/d3.v3.min.js
使用 (v3) 它又可以工作了。
https://d3js.org/d3.v3.min.js