【问题标题】:How to convert a force graph to none in Echarts?如何在 Echarts 中将力图转换为无?
【发布时间】:2021-03-01 01:49:17
【问题描述】:

这段代码我写在https://echarts.apache.org/examples/zh/editor.html?c=graph-simple

option = {
    series: [
        {
            type: 'graph',
            layout: 'force',
            roam: true,
            force: {
                repulsion: 100
            },
            data: [{
                x: null,
                y: null
            }, {
                x: null,
                y: null
            }, {
                x: null,
                y: null
            }, {
                x: null,
                y: null
            }],
        }
    ]
};
myChart.on('click', function (params) {
        if (params.componentType === 'series') {
            if (params.componentSubType === 'graph') {
                option.series[0].layout = 'none'
                const graphNodes = myChart._chartsMap["_ec_\u0000series\u00000\u00000_series.graph"]._symbolDraw._data.graph.data._graphicEls
                for (let i = 0; i < graphNodes.length; i ++ ) {
                    option.series[0].data[i].x = graphNodes[i].x
                    option.series[0].data[i].y = graphNodes[i].y
                }
                myChart.setOption(option)
            }
        }
    });
    myChart.setOption(option);

但是当点击节点时,位置不正确。

demo here

echarts 版本是 5.0.2。

【问题讨论】:

    标签: javascript html echarts apache-echarts


    【解决方案1】:

    我相信它会按预期工作,因为新位置是相对于它们之前的位置而不是中心计算的。这是点击事件后选项对象的sn-p。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多