最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to display data from a JSON object with sigma.js - Stack Overflow

programmeradmin0浏览0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 16

Add your data as follows:

s = new sigma({ 
        graph: data,
        container: 'container',
        settings: {
            defaultNodeColor: '#ec5148'
        }
});

See also: json-is-not-read-by-sigma-js

发布评论

评论列表(0)

  1. 暂无评论