我想在我的网络界面上可视化 Neo4j 图形。所以我正在使用Netwok
. Vis.js
当我在这个例子中指定 JSON 文件时,它工作正常:
var container = document.getElementById('graph');
var options = {
clickToUse : true,
edges: {
},
nodes: {
}
};
var json= {
"nodes":[
{
"id":"203437",
"label":"test",
"properties":{"id":"1","name":"test","uuid":"23e0a5f0-9f73-11e7-a866-7427e54567dc3"}
},
{
"id":"200624",
"label":"test 2",
"properties":{"id":"2","name":"test 2","uuid":"045ea890-9f72-11e7-a866-7427ea637dc3"}
}
],
"relationships":[
{
"id":"164107",
"type":"IS_IN",
"from":200624,
"to":203437,
"properties":[]
}
]
};
var g = {
nodes: json.nodes,
edges: json.relationships
};
var network = new vis.Network(container, g, options);
但是当我尝试使用此JavaScript
功能检索它时:
getDataFromCypherQuery: function(request, callback) {
var json = {
"query": "MATCH path= (I:Person)-[IS_IN*1..1]-() WHERE I.name=~'.*" + request + ".*' RETURN path"
};
var res = $http.post( NEO4J_URL, json, config)
.success(function(data) {
if (callback && callback.success && typeof(callback.success) === 'function') {
callback.success(data);
}
})
.error(function() {
if (callback && callback.error && typeof(callback.error) === 'function') {
callback.error();
}
});
return res;
}
它不起作用,因为JSON
结果不一样并且不尊重vis.Network
预期的结构。事实上,我用这个函数得到的结果是这样的:
"nodes":[
{"http://localhost:7474/db/data/node/203437"},
{"http://localhost:7474/db/data/node/200624"}
]
"relationships": [
{"http://localhost:7474/db/data/relationship/164107"}
]
因此JSON
,我没有获取格式的详细信息,而是获取到节点或关系的链接。我该如何解决?