我只关注felix-kling上的例子。但它只是抱怨Uncaught TypeError: Cannot read property 'getComputedStyle' of null
。我正在使用chrome。当我从anotherOne复制示例时,会发生同样的错误。任何想法的人?
<!DOCTYPE html>
<html>
<head>
<title>JSNetworkX images as nodes demo</title>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script type="text/javascript" src="jsnetworkx.js"></script>
</head>
<body>
<div id="canvas"></div>
<script type="text/javascript">
var G = jsnx.Graph();
G.add_nodes_from([
[1,{color:'red'}],
[2,{color:'green'}],
[3,{color:'white'}]
]);
G.add_edges_from([[1,2],[1,3]]);
jsnx.draw(G,{
element: '#demo-canvas',
node_style: {
fill: function(d) {return d.data.color || '#AAA';}
}
});
</script>
</body>
</html>
答案 0 :(得分:2)
你没有id为demo-canvas
的元素,所以没有要绘制的元素......你的元素被称为canvas
所以......:
jsnx.draw(G,{
element: '#canvas',
node_style: {
fill: function(d) {return d.data.color || '#AAA';}
}
});