Javascript D3.js圆图布局未显示TypeError
我几乎是从中复制了代码,但无法使其正常工作 以下是html文件:Javascript D3.js圆图布局未显示TypeError,javascript,d3.js,data-visualization,Javascript,D3.js,Data Visualization,我几乎是从中复制了代码,但无法使其正常工作 以下是html文件: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Vizualizace dat</title> <!--set the location of d3.js script as local, to make i
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Vizualizace dat</title>
<!--set the location of d3.js script as local, to make it work offline-->
<script type="text/javascript" src="../D3_library/d3.v3.js"></script>
<script type="text/javascript" src="sepC_script_V3_noedit.js"></script>
<style>
body {
font-family: 'Source Sans Pro', sans-serif;
font-weight: 300;
}
b {
font-weight: 900;
}
.outline {
fill: none;
stroke: #888888;
stroke-width: 1px;
}
#tooltip {
font-size: 10pt;
font-weight: 900;
fill: #000000;
stroke: #ffffff;
stroke-width: 0.25px;
}
.node {
stroke: #ffffff;
stroke-weight: 1px;
}
.link {
fill: none;
stroke: #888888;
stroke-weight: 1px;
stroke-opacity: 0.5;
}
.highlight {
stroke: red;
stroke-weight: 4px;
stroke-opacity: 1.0;
}
</style>
</head>
<body>
<script type="text/javascript">
sep_script()
</script>
</body>
</html>
我得到的是这个错误:
TypeError:null不是对象(正在计算“graph.links”)
它说这条线有一个问题:
graph.links.forEach(function(d, i) {
表示null不是对象(计算“graph.links”)
我觉得这只不过是一件小事,但我不知道是哪件事。我真的不知道问题出在哪里。它在Chrome中工作,而不是在Safari中。现在,当我更改了我的原始数据时,它甚至开始在Safari中工作。(祈祷它能继续工作)如何获得它的
graph
参数?它工作得非常好。这里:您提到的错误“null
不是对象”是当d3.selection
失败时的错误(即未找到HTML元素)。你能不能把你所拥有的东西写一个片段?@AshtonFrench我现在也在考虑。但我真的不知道。问题是,为什么完全相同的代码在plnkr上工作…@Shashank-hah,你是对的,它在plnkr.co上运行。我在MacBook上粘贴了完全相同的代码,在MacBook上我通过python运行本地服务器。它在那里工作,但在我的MacBook上还是不行,奇怪:/–@Shashank哈哈,伙计们,它在Chrome上工作没有问题。但Safari仍在抛出错误…有什么想法吗?
{
"nodes":[
{"name":"Myriel","group":1},
{"name":"Napoleon","group":1},
...
{"name":"Brujon","group":4},
{"name":"Mme.Hucheloup","group":8}
],
"links":[
{"source":1,"target":0,"value":1},
{"source":2,"target":0,"value":8},
...
{"source":76,"target":48,"value":1},
{"source":76,"target":58,"value":1}
]
graph.links.forEach(function(d, i) {