关系图中,节点的name属性重名时报错
(echarts.min.js:32 Uncaught TypeError: Cannot set property 'dataIndex' of undefined)
希望将节点的显示用的名称与节点的标识分离,不然,无法处理名称相同,位置不同、值不同的情况。
1.
2.
用于显示的节点名称相同,依然可以通过唯一标识绘制节点。
节点名称作为全局唯一id处理,无法应用到节点名称相同而节点值不同的情况。
option = {
title: {
text: 'Graph 简单示例'
},
tooltip: {},
animationDurationUpdate: 1500,
animationEasingUpdate: 'quinticInOut',
series : [
{
type: 'graph',
layout: 'none',
symbolSize: 50,
roam: true,
label: {
normal: {
show: true
}
},
edgeSymbol: ['circle', 'arrow'],
edgeSymbolSize: [4, 10],
edgeLabel: {
normal: {
textStyle: {
fontSize: 20
}
}
},
data: [{
name: '节点1',
value: 10,
x: 300,
y: 300
}, {
name: '节点2',
value: 20,
x: 800,
y: 300
}, {
name: '节点3',
value: 30,
x: 550,
y: 100
}, {
name: '节点4',
value: 40,
x: 550,
y: 500
}, {
name: '节点4',
value: 40,
x: 850,
y: 500
}],
// links: [],
links: [{
source: 0,
target: 1,
symbolSize: [5, 20],
label: {
normal: {
show: true
}
},
lineStyle: {
normal: {
width: 5,
curveness: 0.2
}
}
}, {
source: '节点2',
target: '节点1',
label: {
normal: {
show: true
}
},
lineStyle: {
normal: { curveness: 0 }
}
}, {
source: '节点1',
target: '节点3'
}, {
source: '节点2',
target: '节点3'
}, {
source: '节点2',
target: '节点4'
}, {
source: '节点1',
target: '节点4'
}],
lineStyle: {
normal: {
opacity: 0.9,
width: 2,
curveness: 0
}
}
}
]
};
节点标识可以用 id
我也遇到了同样的问题, 通过向data项中添加id字段, 解决了这个问题, 所以贴上代码片段, 方便初学者解决这个问题.
data = [{
id: 1,
name: '重复',
x: 0,
y: 0
}, {
id: 2,
name: '重复',
x: 200,
y: 0
}]
Most helpful comment
节点标识可以用
id