所以我正在尝试学习SigmaJS,并且很难理解如何在这个codepen中将data.json传递给JS:
http://codepen.io/eternalminerals/pen/GpqNLQ
例如,http://sigmajs.org/网站有一个简单示例如下:
数据:
{
"nodes": [
{
"id": "n0",
"label": "A node",
"x": 0,
"y": 0,
"size": 3
},
{
"id": "n1",
"label": "Another node",
"x": 3,
"y": 1,
"size": 2
},
{
"id": "n2",
"label": "And a last one",
"x": 1,
"y": 3,
"size": 1
}
],
"edges": [
{
"id": "e0",
"source": "n0",
"target": "n1"
},
{
"id": "e1",
"source": "n1",
"target": "n2"
},
{
"id": "e2",
"source": "n2",
"target": "n0"
}
]
}
HTML:
<html>
<head>
<style type="text/css">
#container {
max-width: 400px;
height: 400px;
margin: auto;
}
</style>
</head>
<body>
<div id="container"></div>
<script src="sigma.min.js"></script>
<script src="sigma.parsers.json.min.js"></script>
<script>
sigma.parsers.json('data.json', {
container: 'container',
settings: {
defaultNodeColor: '#ec5148'
}
});
</script>
</body>
</html>
我尝试传递data.json,如下所示:
sigma.parsers.json('http://eternalminerals.com/data/data.json', {
container: 'container',
settings: {
defaultNodeColor: '#ec5148'
}
});
但它似乎没有用。如果data.json文件位于http://eternalminerals.com/data/data.json,你如何传入data.json?