【问题标题】:Exporting nodes and links from zoomcharts从 zoomcharts 导出节点和链接
【发布时间】:2014-04-07 12:56:46
【问题描述】:

我正在导出节点和链接到这样的 json 对象,以便稍后将其写入磁盘。这是我加载时的数据:

{
"nodes": [
    {
        "id": "a1",
        "type": "activity",
        "loaded": true,
        "style": {"label": "Testing ZoomCharts"}
    },
    {
        "id": "o1",
        "type": "organization",
        "loaded": true,
        "style": {"label": "Ophileon"}
    }
],
"links": [{
    "id": "l1",
    "from": "o1",
    "to": "a1",
    "style": {"label": "Executes"}
}
}

当我从当前图表中获取节点和链接时,像这样

    function exportNodes(){
      var nodesandlinks = {"nodes":[],"links":[]};
      nodesandlinks.nodes.push(chart._scene.data.nodes);
      nodesandlinks.links.push(chart._scene.data.links);
      alert(JSON.stringify(nodesandlinks));
    }

它返回一个结果,我需要再次处理才能重新加载它,因为它具有每个节点作为属性。

{
"nodes": [{
    "a1": {
        "id": "a1",
        "type": "activity",
        "loaded": true,
        "style": {"label": "Testing ZoomCharts"}
    },
    "o1": {
        "id": "o1",
        "type": "organization",
        "loaded": true,
        "style": {"label": "Ophileon"}
    }
}],
"links": [{"l1": {
    "id": "l1",
    "from": "o1",
    "to": "a1",
    "style": {"label": "Executes"}
}}]
}

还有其他方法可以检索节点吗?我已经试过了:

chart.data.nodes
TypeError: Cannot read property 'nodes' of undefined

chart.nodes
function (){return this._impl.scene.nodes()} 

【问题讨论】:

    标签: zoomcharts


    【解决方案1】:

    现在有一个专用的 API 函数用于从网络图表中导出数据:

    var exportedData = chart.exportData(visibleOnly);
    alert(JSON.stringify(exportedData));
    

    https://zoomcharts.com/developers/en/net-chart/api-reference/api/#NetChart.exportData

    【讨论】:

      【解决方案2】:

      怎么样:

        function exportNodes(){
            var nodesandlinks = {"nodes":[],"links":[]};
            for (var n in chart._scene.data.nodes){
                nodesandlinks.nodes.push(chart._scene.data.nodes[n]);
            }
            for (var l in chart._scene.data.links){
                nodesandlinks.links.push(chart._scene.data.links[l]);
            }
            alert(JSON.stringify(nodesandlinks));
        }
      

      【讨论】:

      • 太棒了 :) 但是必须这样做是故意的吗?只是导出 chart.data.nodes 和 chart.data.links 是我所期望的。
      • 我相信未来我们会有更精简的选项,因为我们还计划引入一些编辑功能。访问 _scene 有点棘手,不应该长期依赖:)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多