web组织架构实现

其他方法更好方法,还待研究,希望各位可以共享,或者有更好的echarts树图的新需求,欢迎留言

使用echarts中的树图进行实现需求

https://echarts.apache.org/zh/option.html#series-tree.leaves.labelicon-default.png?t=N7T8https://echarts.apache.org/zh/option.html#series-tree.leaves.label1.实现组织架构的生成

2.自定义提示框

   在data中自定义提示框,书写html标签等,也可以直接在echarts中的option中书写函数

    知识点:照片的显示,需要照片路径前后加空格

//修改鼠标悬停显示的内容 
formatter:   function(params){
            //  console.log(this.perImgUrl,'this.perImgUrl');
            // 基本路径console.log(this.$axios.defaults.baseURL,'this.$axios.defaults.baseURL')
        var imgeUrl=perImgUrl+params.data.avatar;
        return (
              //  console.log(imgeUrl,'imgsimgsimgs'),
       '<img style="width:100%;height:120px;padding:5px" src="'+imgeUrl+'"/>'
               + "<br>" +
       '<span style="padding-left:5px;height:30px;line-height:30px;display: inline-block;">性别:' +
          (params.data.sex==null ? '数据暂未录入' : params.data.sex==1 ? '男' : '女') +
        "</span>" +
        "<br>" +
        '<span style="padding-left:5px;height:30px;line-height:30px;display: inline-block;">级别:' +params.data.roleName +
        "</span>" +
         "<br>" +
        '<span style="padding-left:5px;height:30px;line-height:30px;display: inline-block;">手机号:' +params.data.phone +
        "</span>" +
        "<br>" +
        '<span style="padding-left:5px;height:30px;line-height:30px;display: inline-block;">所属地区:' + params.data.departName +
        "</span>" +
        "<br>"
       );
   } 

3.同节点层只能展开一个下节点,下节的其他节点自动关闭

在option外面进行写入,默认进来只显示二级

  if (option && typeof option === "object") {
        myChart.setOption(option, true);
        myChart.on('mousedown', (e) => {
           var container = document.getElementById('main');
          const name = e.data.name;
          const curNode = myChart._chartsViews[0]._data.tree._nodes.find(item => {
            return item.name === name;
          });
          console.log(curNode,'curNodecurNodecurNode');
          const depth = curNode.depth;
          const curIsExpand = curNode.isExpand;
          myChart._chartsViews[0]._data.tree._nodes.forEach((item, index) => {
            if (item.depth === depth && item.name !== name && !curIsExpand) {
              item.isExpand = false;
            } 
          });
        }) 
    }

4.树图高度动态变化(还待研究)

完整代码

  getOption() {
      var myChart = echarts.init(this.$refs.lineChart);
      console.log(this.perImgUrl,'父级传过来的ueridthis.$axios.defaults.baseURL'); 
      var perImgUrl=this.perImgUrl
      // console.log(this.namedata,"图表里的数据")
      var option = {
        tooltip: {
          trigger: "item",
          triggerOn: "mousemove",
          backgroundColor: "#1e1e1e",
          enterable: true, //鼠标是否可进入提示框浮层中
          formatter:   function(params){
            //  console.log(this.perImgUrl,'this.perImgUrl');
            // console.log(this.$axios.defaults.baseURL,'this.$axios.defaults.baseURL')
             var imgeUrl=perImgUrl+params.data.avatar;
             return (
              //  console.log(imgeUrl,'imgsimgsimgs'),
               '<img style="width:100%;height:120px;padding:5px" src="'+imgeUrl+'"/>'
               + "<br>" +
               '<span style="padding-left:5px;height:30px;line-height:30px;display: inline-block;">性别:' +
               (params.data.sex==null ? '数据暂未录入' : params.data.sex==1 ? '男' : '女') +
               "</span>" +
               "<br>" +
               '<span style="padding-left:5px;height:30px;line-height:30px;display: inline-block;">级别:' +
               params.data.roleName +
               "</span>" +
               "<br>" +
               '<span style="padding-left:5px;height:30px;line-height:30px;display: inline-block;">手机号:' +
               params.data.phone +
               "</span>" +
               "<br>" +
               '<span style="padding-left:5px;height:30px;line-height:30px;display: inline-block;">所属地区:' +
               params.data.departName +
               "</span>" +
               "<br>"
             );
      } //修改鼠标悬停显示的内容
        },
        series: [
          {
            type: "tree",
            id: 0,
            name: "tree1",
            data: this.namedata,
            top: "0%",
            left: "10%",
            bottom: "0%",
            right: "15%",
            symbol: "image",
            avoidLabelOverlap: true,//防止标签重叠
            //  节点的大小
            symbolSize: 25,
            //  连接线默认是曲线,polyline显示直线
            edgeShape: "polyline",
            edgeForkPosition: "63%",
            initialTreeDepth: 1,
            //  连接线的样式
            lineStyle: {
              width: 2
            },
            //节点的颜色
             itemStyle: {
                 //节点合住的颜色
                  // color: '#03a489',
                 //  节点展开的颜色
                  borderColor: '#e3e3e3',
              },
            label: {
              // backgroundColor: "#048e7a",
              color: "#fff",
              fontSize: "15",
              width: 10,
              overflow: "truncate",
              padding: [4, 4, 2, 4],
              position: "left",
              verticalAlign: "middle",
              align: "right"
            },
            //  最后的叶子节点
            leaves: {
              label: {
                position: "right",
                verticalAlign: "middle",
                align: "left"
              }
            },
            emphasis: {
              focus: "descendant"
            },
            //  expandAndCollapse属性表示是否可以展开和折叠节点
            expandAndCollapse: true,
            //  animationDuration和animationDurationUpdate属性表示动画时长。
            animationDuration: 550,
            animationDurationUpdate: 750
          }
        ]
        
      };
      // console.log(option.series[0].data,"图表渲染完的数据====")
      if (option && typeof option === "object") {
        myChart.setOption(option, true);
        myChart.on('mousedown', (e) => {
           var container = document.getElementById('main');
          const name = e.data.name;

          const curNode = myChart._chartsViews[0]._data.tree._nodes.find(item => {
            return item.name === name;
          });
          console.log(curNode,'curNodecurNodecurNode');
          const depth = curNode.depth;
          const curIsExpand = curNode.isExpand;
          myChart._chartsViews[0]._data.tree._nodes.forEach((item, index) => {
            if (item.depth === depth && item.name !== name && !curIsExpand) {
              item.isExpand = false;
            } 
           
          });
        })
        
      }
  // let elesArr = Array.from(new Set(myChart._chartsViews[0]._data._graphicEls));
  //       let dep=myChart._chartsViews[0]._data.tree.root.height;//获取树高
  //       let layer_height=100;     //层级之间的高度
  //       let currentHeight = layer_height * (dep+1) || layer_height;
  //       let newHeight = Math.max(currentHeight, layer_height);
  //       this.chartHeight=newHeight+'px';
  //       let layer_width = 100; // 兄弟节点之间的距离
  //       let currentWidth = layer_width * (elesArr.length - 1) || layer_width;
  //       let newWidth = Math.max(currentWidth, layer_width);
  //       this.chartWidth=newWidth+'px';
  //       myChart.resize();

        
          
      // var allNode = 0;
      // var nodes = myChart._chartsViews[0]._data._graphicEls;
      // console.log(myChart._chartsViews[0]._data._graphicEls,'myChart._chartsViews[0]');
      // //大于35个在计算高度
      // if(nodes.length>5){ 
      //   for (var i = 0, count = nodes.length; i < count; i++) {
      //     var node = nodes[i];
      //     if (node === undefined)
      //       continue;
      //     allNode++;
      //   }
      //   console.log(allNode,'allNode');
      //   var height = 500;
      //   console.log(window.innerHeight);
      //   var currentHeight = 55*allNode;
      //   var newWidth = Math.max(currentHeight, height);
      //   this.height = newWidth
      //   console.log('currentHeight',currentHeight,',height',newWidth)
      //   // this.$refs.lineChart.style.width = window.innerWidth + 'px';
      //   this.$refs.lineChart.style.height = newWidth + 'px';
      //   myChart.resize();
      // }
      option && myChart.setOption(option);
    },

其他方法更好方法,还待研究,希望各位可以共享,或者有更好的echarts树图的新需求,欢迎留言

  • 9
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值