echarts icon indicating copy to clipboard operation
echarts copied to clipboard

关系图节点自己实现拖拽不成功

Open maoyr opened this issue 8 years ago • 0 comments

One-line summary [问题简述]

参考教程‘小例子:自己实现拖拽’,自己写的关系图拖拽,代码见下,并不成功,请问哪里有问题?

Version & Environment [版本及环境]

  • ECharts version [ECharts 版本]: 最新版
  • Browser version [浏览器类型和版本]: chrome
  • OS Version [操作系统类型和版本]:

Expected behaviour [期望结果]

请问如何自己实现关系图节点拖拽?

ECharts option [ECharts配置项]

var data = [{
    name: '节点1',
    x: 100,
    y: 100
}, {
    name: '节点2',
    x: 200,
    y: 200
}];
option = {
    series : [
        {
            id: 'a',
            type: 'graph',
            layout: 'none',
            symbolSize: 50,
            //roam: true,
            label: {
                normal: {
                    show: true
                }
            },
            edgeSymbol: ['circle', 'arrow'],
            edgeSymbolSize: [4, 10],
            edgeLabel: {
                normal: {
                    textStyle: {
                        fontSize: 20
                    }
                }
            },
            data: data,
            links: [ {
                source: '节点1',
                target: '节点2'
            }]
        }
    ]
};


if (!app.inNode) {
    setTimeout(function () {
        // Add shadow circles (which is not visible) to enable drag.
        myChart.setOption({
            graphic: echarts.util.map(data, function (item, dataIndex) {
                var coordinate = [item.x,item.y];

                return {
                    type: 'circle',
                    position: myChart.convertToPixel({seriesIndex: 0},coordinate),
                    shape: {
                        cx: 0,
                        cy: 0,
                        r: 10
                    },
                    invisible: true,
                    draggable: true,
                    ondrag: echarts.util.curry(onPointDragging, dataIndex),
                    z: 100
                };
            })
        });
    }, 0);

}


function onPointDragging(dataIndex, dx, dy) {
    console.log(this.position);
    var coordinate = myChart.convertFromPixel({seriesIndex: 0}, this.position);
    data[dataIndex].x = coordinate[0];
    data[dataIndex].y = coordinate[1];
    
    

    // Update data
    myChart.setOption({
        series: [{
            id: 'a',
            data: data
        }]
    });
}

Other comments [其他信息]

maoyr avatar Feb 07 '18 10:02 maoyr