0

I write this code in 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);

but when click on the node, position is not correct.

demo here

echarts version is 5.0.2.

junjie.X
  • 1
  • 2

1 Answers1

0

I believe it works as intended as the new positions are calculated relative to their previous position and not the center. here is a snippet of option object after the click event.enter image description here

Takashi
  • 11
  • 2