Need help in creating network graph using visjs in

2019-05-17 07:13发布

I need help in making this plunker work something similar to this vis example in angularjs.

I am using <vis-network data="data" options="options"></vis-network> tag and below data and options

data

var nodes = [
  {id: 1, label: 'Node 1'},
  {id: 2, label: 'Node 2'},
  {id: 3, label: 'Node 3'},
  {id: 4, label: 'Node 4'},
  {id: 5, label: 'Node 5'}
];
var edges = [
  {from: 1, to: 3},
  {from: 1, to: 2},
  {from: 2, to: 4},
  {from: 2, to: 5}
];
$scope.data = VisDataSet({
  nodes: nodes,
  edges: edges
});

options

$scope.options = {
  autoResize: true,
  height: '100%',
  width: '100%'
};

There is no console error, what am I missing. Please help.

1条回答
干净又极端
2楼-- · 2019-05-17 07:40

Your data is plain object, however nodes & edges should be an object of VisDataSet

var nodes = VisDataSet([
  {id: 1, label: 'Node 1'},
  {id: 2, label: 'Node 2'},
  {id: 3, label: 'Node 3'},
  {id: 4, label: 'Node 4'},
  {id: 5, label: 'Node 5'}
]);
var edges = VisDataSet([
  {from: 1, to: 3},
  {from: 1, to: 2},
  {from: 2, to: 4},
  {from: 2, to: 5}
]);
$scope.data = {
  nodes: nodes,
  edges: edges
};

I have updated your plunker here.

查看更多
登录 后发表回答