/analymation/graphTest是调用get_graph方法的url视图.py我无法从我的方法中获取json以返回到d3.json函数中。我怎么能做到呢?我要做的是类似于使用d3.json在图上显示内容的https://github.com/neo4j-examples/movies-python-bolt。是不是因为python版本不同,导致我的应用程序与代码示例不同?我还打印出了图形[0]的值。它表明图[0]是未定义的。在
在视图.py在
def get_graph(request):
db = get_db()
results = db.run("MATCH (m:Movie)<-[:ACTED_IN]-(a:Person) "
"RETURN m.title as movie, collect(a.name) as cast ")
nodes = []
rels = []
i = 0
for record in results:
nodes.append({"title": record["movie"], "label": "movie"})
target = i
i += 1
for name in record['cast']:
actor = {"title": name, "label": "actor"}
try:
source = nodes.index(actor)
except ValueError:
nodes.append(actor)
source = i
i += 1
rels.append({"source": source, "target": target})
return render(request, 'anomaly/index.html',{"nodes": nodes, "links": rels})
在索引.html在
^{pr2}$调用get_graph方法时返回的Json示例
{"nodes": [{"title": "Apollo 13", "label": "movie"}, {"title": "Tom Hanks", "label": "actor"}, {"title": "Kevin Bacon", "label": "actor"}
更新1: 我目前能够检索到数据并成功地解析到我的javascript函数中,但是当我在javascript函数中打印值时,它显示了我意想不到的奇怪符号。在
javascript奇怪的json
[{'title': 'Apollo 13', 'label': 'movie'}, {'title': 'Tom Hanks', 'label': 'actor'}, {'title': 'Kevin Bacon', 'label': 'actor'},
目前没有回答
相关问题 更多 >
编程相关推荐