0

我在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);

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

演示在这里

echarts 版本是 5.0.2。

4

1 回答 1

0

我相信它可以按预期工作,因为新位置是相对于它们之前的位置而不是中心计算的。这是单击事件之后的选项对象片段。在此处输入图像描述

于 2021-08-10T20:12:29.647 回答