gojs节点水平排列,连接线上加文字

 

效果图如下

本来打算蛇形排列,但是引入js老是报错,所以采用平行排列

代码如下

定义一个div,定义两个参数 

 <el-row  height="100%">
            <el-col :span="24">
              <div id="parentDiv">
                <div id="mygoChart" class="mygoChart" :style="{'width': '100%',height:mygoChartHeight+'px'}"></div>
              </div>
            </el-col>
          </el-row>
//初始化gojs
    initGoJS() {
      var $ = go.GraphObject.make; // for conciseness in defining templates
     
      const computerImg = require("./../assets/img/route.png");
      const routeImg = require("./../assets/img/computer.png");
      var myDiagram = $(
        go.Diagram,
        "mygoChart", // create a Diagram for the DIV HTML element
        //  {
        //     //isTreePathToChildren: false,  // links go from child to parent
        //     // layout: $(SerpentineLayout)  // defined in SerpentineLayout.js
        //   }
          {
          "undoManager.isEnabled": true,
          layout: $(
            go.TreeLayout, // 1个特殊的树形排列 Diagram.layout布局
            {
              angle: 0, //90可以竖直排列
              layerSpacing: 60
            }
          )
        }
      );
       
      myDiagram.nodeTemplate = $(
        go.Node,
        "Vertical",
        { locationSpot: go.Spot.Center },
        $(
          go.Picture,
          "Vertical",
          computerImg,
          // 通常情况下,图片需要有明确的宽度。当没有设置图片路径 或者 图片是透明的时候会显示红色背景,
          { width: 60, height: 60,margin:new go.Margin(0, 0, 0, 0) }, //设置节点之间的边距
           new go.Binding("source", "url")
        ),

        $(
          go.TextBlock,

          //"Default Text111",
          {
            stroke: "#909399",
            font: "bold 16px sans-serif",
            textAlign: "center"
          }, // 初始化文本样式

          new go.Binding("text", "text")
        ), // 绑定数据的key
        {
          //  define a tooltip for each node that displays its information
          toolTip: $(
            "ToolTip",
            $(
              go.TextBlock,
              { margin: 4, font: " 16px sans-serif" },
              // "Default Text111",
              new go.Binding("text", "", function(model, obj) {
                var x = obj.panel.adornedPart; // the object that the mouse is over
                return x.data.ipstr;
              })
            )
          )
        }
      );
     myDiagram.linkTemplate =
        $(go.Link,   // slightly curved, by default
        
          { routing: go.Link.Bezier, corner: 0},
           $(go.Shape, { strokeWidth: 2, stroke: "#555" }),
            $(go.Shape, {toArrow: 'OpenTriangle'}),
          $(go.TextBlock,  // show the second path object name, if any
            { segmentOffset: new go.Point(0, -12) },//设置文字在线之上
            new go.Binding("text", "text"))
        );
        
  
      this.nodeDataArray = [
        { key: 1, text: "美国",url : require("./../assets/img/route.png")},
        { key: 2, text: "加拿大" ,url:require("./../assets/img/computer.png")},
        { key: 3, text: "中国 香港 香港"  },
        { key: 4, text: "中国 陕西 西安" },
        { key: 5, text: "中国 北京 北京"},
        { key: 6, text: "中国 上海 上海" },
        { key: 7, text: "中国 深圳 深圳" },
        { key: 8, text: "中国 深圳 深圳" },
        { key: 9, text: "中国 深圳 深圳" },
        { key: 10, text: "中国 深圳 深圳1" },
        { key: 11, text: "中国 深圳 深圳2" },
        { key: 12, text: "中国 深圳 深圳3" },
        { key: 13, text: "中国 深圳 深圳4" },
        { key: 14, text: "中国 深圳 深圳5" },
        { key: 15, text: "中国 深圳 深圳6" }
      ];
    
      this.linkDataArray = [
        { from: 1, to: 2,text :"39ms" },
        { from: 2, to: 3,text :"63ms"},
        { from: 3, to: 4,text :"59ms"},
        { from: 4, to: 5},
        { from: 5, to: 6},
        { from: 6, to: 7},
        { from: 7, to: 8},
        { from: 8, to: 9},
        { from: 9, to: 10},
        { from: 10, to: 11},
        { from: 11, to: 12},
        { from: 12, to: 13},
        { from: 13, to: 14},
        { from: 14, to: 15},

      ];
      myDiagram.model = new go.GraphLinksModel(
        this.nodeDataArray,
        this.linkDataArray
      );
    }

直接在别的地方调用即可

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

www.365codemall.com

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值