【问题标题】:Cytoscape js - Initiliaze the graph using cytoscape-graphml.jsCytoscape js - 使用 cytoscape-graphml.js 初始化图形
【发布时间】:2020-02-13 04:53:52
【问题描述】:

我有一个 graphML 文件。我想在浏览器上显示我的 graphML 文件中的图形。我正在使用 cytoscape.js。据我了解,我们可以使用 cytoscape 扩展 cytoscape-graphml.js 从 graphML 文件中导入图形。但我不知道该怎么做。这是我想要实现的示例。

var cy;
fetch('http://localhost/Development/example.graphml')
.then(response => response.text())
.then((data) => {
   cy = cytoscape({
     container: document.getElementById('cy'),
     elements: data
   });
});

【问题讨论】:

    标签: cytoscape.js


    【解决方案1】:

    好吧,正如您在 cytoscape.js-graphml 的 docs 中看到的那样,您只需要使用 graphml 数据和如下布局来初始化 cytoscape:

    var cy;
    fetch('http://localhost/Development/example.graphml')
    .then(response => response.text())
    .then((data) => {
       cy = cytoscape({
         container: document.getElementById('cy'),
         style: [
            {
                selector: 'node',
                style: {
                    'content': 'data(id)'
                }
            },
            {
                selector: 'edge',
                style: {
                    'target-arrow-shape': 'triangle'
                }
            }
        ],         
        ready: function () {
            this.graphml({layoutBy: 'cose'});
            this.graphml(data);
        }
      });
    });
    

    【讨论】:

    • 我收到此错误:“未捕获(承诺中)类型错误:this.graphml 不是函数”。有什么想法吗?
    • 如果你遵循文档,你应该让它正常工作。您是否在 HTML 文件中忘记了 jquery?
    猜你喜欢
    • 2017-08-28
    • 1970-01-01
    • 2016-02-28
    • 2017-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多