Incubator-echarts: 绘制关系图时,节点的name属性重名后报错

Created on 31 May 2016  ·  2Comments  ·  Source: apache/incubator-echarts

问题简述 (One-line summary)

关系图中,节点的name属性重名时报错
(echarts.min.js:32 Uncaught TypeError: Cannot set property 'dataIndex' of undefined)
希望将节点的显示用的名称与节点的标识分离,不然,无法处理名称相同,位置不同、值不同的情况。

版本及环境 (Version & Environment)

  • ECharts 版本 (ECharts version): 3.1.10
  • 浏览器类型和版本 (Browser version): chrome 51.0.2704.63 m
  • 操作系统类型和版本 (OS Version): window7 x64

    重现步骤 (Steps to reproduce)

1.
2.

期望结果 (Expected behaviour)

用于显示的节点名称相同,依然可以通过唯一标识绘制节点。

可能哪里有问题 (What went wrong)

节点名称作为全局唯一id处理,无法应用到节点名称相同而节点值不同的情况。

ECharts配置项 (ECharts option)

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
                }
            }
        }
    ]
};

其他信息 (Other comments)

support

Most helpful comment

节点标识可以用 id

All 2 comments

节点标识可以用 id

我也遇到了同样的问题, 通过向data项中添加id字段, 解决了这个问题, 所以贴上代码片段, 方便初学者解决这个问题.

    data = [{
        id: 1,
        name: '重复',
        x: 0,
        y: 0
    }, {
        id: 2,
        name: '重复',
        x: 200,
        y: 0
    }]
Was this page helpful?
0 / 5 - 0 ratings