I would like to read node/edges information for a graph (sigma.js) from a JSON variable. While it's quite easy to use an external JSON file as input via a JSON parser, I could not find a way to use a JSON object directly defined in the JavaScript code. There seems to exist a method called 'read', but I could not get it to work (Source: .js/wiki/Graph-API). Could someone give me a hint?
This is what I would like to have:
data = {
"nodes": [
{
"id": "n0",
"label": "A node",
"x": 0,
"y": 0,
"size": 3
},
{
"id": "n1",
"label": "Another node",
"x": 3,
"y": 1,
"size": 2
},
],
"edges": [
{
"id": "e0",
"source": "n0",
"target": "n1"
},
]
}
sigma.parsers.json( data , {
container: 'container',
settings: {
defaultNodeColor: '#ec5148'
}
});
Thank you, cheers, Michael
I would like to read node/edges information for a graph (sigma.js) from a JSON variable. While it's quite easy to use an external JSON file as input via a JSON parser, I could not find a way to use a JSON object directly defined in the JavaScript code. There seems to exist a method called 'read', but I could not get it to work (Source: https://github.com/jacomyal/sigma.js/wiki/Graph-API). Could someone give me a hint?
This is what I would like to have:
data = {
"nodes": [
{
"id": "n0",
"label": "A node",
"x": 0,
"y": 0,
"size": 3
},
{
"id": "n1",
"label": "Another node",
"x": 3,
"y": 1,
"size": 2
},
],
"edges": [
{
"id": "e0",
"source": "n0",
"target": "n1"
},
]
}
sigma.parsers.json( data , {
container: 'container',
settings: {
defaultNodeColor: '#ec5148'
}
});
Thank you, cheers, Michael
Share Improve this question asked Apr 24, 2014 at 15:24 mnoldemnolde 1251 gold badge1 silver badge5 bronze badges1 Answer
Reset to default 16Add your data as follows:
s = new sigma({
graph: data,
container: 'container',
settings: {
defaultNodeColor: '#ec5148'
}
});
See also: json-is-not-read-by-sigma-js