使用echarts制作拓扑图

使用echarts制作拓扑图

1.首先是设置option,设置基本属性。

this.option = {
            title: {
                text: '',
            },
            tooltip:{}, 
            // animationDurationUpdate: 10,
            // animationEasingUpdate: 'quinticInOut',
            animationEasing: 'elasticOut',
            animationDelayUpdate: function (idx) {
                return idx * 1;
            },
            grid: {       
                y: '0',
                y2: '0',
                x: '0',
                x2: '0'
            },
            xAxis: {
                type: 'value',
                position: 'top',
            },
            yAxis: {
                inverse: true,
                type: 'value',
            },
            silent: true,
            series : [
                {
                    type: 'graph',
                    layout: 'none',
                    symbolSize: 50,            
                    roam: true,                
                    focusNodeAdjacency:true,   
                    label: {
                        normal: {
                            show: true,       
                            position:'top',
                            fontSize:20
                        }
                    },
                    legend: {  
                        left: 'left',  
                        data:['h1','h2', 'h3']  
                    },
                    edgeSymbol: ['circle', 'circle'],
                    edgeSymbolSize: [1, 1],   
                    edgeLabel: {
                        normal:{
                            show:false
                        },
                        emphasis: {
                            textStyle: {
                                fontSize: 20   
                            }
                        }
                    },
                    animationDelay: function (idx) {
                       return idx * 300;
                    },
                    force: {
                        edgeLength: 5,
                        repulsion: 20,
                        gravity: 0.2
                    },
                    //节点信息
                    data: [],
                    links: [],
                    lineStyle: {
                        normal: {
                            show:true,
                            color: {       
                                type: 'linear',
                                x: 0,
                                y: 0,
                                x2: 0,
                                y2: 1,
                                colorStops: [
                                    {
                                        offset: 0, color: 'red'
                                    }
                                    ,{
                                        offset: 1, color: 'blue' 
                                    }
                                ],
                                globalCoord: false
                            },     
                        },
                        emphasis:{
                            color:'red',
                            width:3,
                            type:'dashed',
                        }
                    },      
                    tooltip: {
                        position:'bottom',                      
                        backgroundColor:'green',
                        textStyle:{
                            fontSize:18,
                        }
                    }
                }
            ]
        };
    this.option.series[0].data = this.nodes;
    this.option.series[0].links = this.links;
    this.myChart.setOption(this.option);

设置option,然后setOption即可。
在制作的过程中,还是遇到了一些问题,比如因为需要给拓扑图的每个node的设置了一个id,先给已知节点设置了id,然后根据后台传过来的数据再重新设置id,此时,拓扑图上的节点的连线全部消失了。及时links的数据仍在。后来查其原因,就是因为之前设置了id,之后又改变了id,才造成了node与links之间‘失联’了。所以,echarts里面要慎用id这个属性

  1. 设置节点为指定图片
nodes: [
    {
        {
              name:'1',
              value: 0,
              label: {
                    normal: {
                          show: true,
                          position: 'bottom',
                          fontSize: '12'
                   }
              },
              symbol: 'image://http://oow60tecr.bkt.clouddn.com/firewall.png',
              symbolSize: [40, 40],
              x:300,
              y:120
        }
    }
]

节点设置成类似上面的形式即可。主要是设置image,我之前用的是本地图片,用的相对路径,一直是404,最后换成了远程地址图片。
部分效果图如下:

  • 13
    点赞
  • 33
    收藏
    觉得还不错? 一键收藏
  • 8
    评论
Echarts可以用来画拓扑图,通过设置坐标系和节点的位置,可以展现节点之间的关系数据。在使用Echarts拓扑图时,可以使用series-graph来展示节点和节点之间的关系数据。设置option后,使用setOption即可生成拓扑图。在制作过程中,可能会遇到一些问题,比如设置了节点的id后又改变了id,可能会导致节点与连线之间的关联丢失。因此,在Echarts使用id属性时需要慎重。可以通过设置节点的坐标和使用二维直角坐标系(笛卡尔坐标系)来确定节点的位置。具体设置可以在series中的相应类型下,将coordinateSystem设置为cartesian2d。\[1\]\[2\]\[3\] #### 引用[.reference_title] - *1* *3* [使用echarts画设备拓扑图](https://blog.csdn.net/github_35631540/article/details/115246658)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [使用echarts制作拓扑图](https://blog.csdn.net/github_38402037/article/details/79154797)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值