美文网首页
echarts 树图 右键操作,多个节点展示详情框

echarts 树图 右键操作,多个节点展示详情框

作者: 吃肉肉不吃肉肉 | 来源:发表于2022-11-07 17:52 被阅读0次

效果:


4c3a619546ae95262e614431c61ffd6.jpg
<div id="main" ref="main" style="width: 80%;height: 800px;padding:30px 100px 30px 30px" />
    <el-card v-for="(item, i) in infoList" :id="u+i" :key="i" class="info">
      <div class="info_flex">
        <el-image
          :src="item.headimgurl"
          fit="fill"
          :preview-src-list="[item.headimgurl]"
          class="info_img"
        />
        <div class="info_flexl info_wid">
          <span>昵称:{{ item.nickname }}</span>
          <span>姓名:{{ item.realname }}</span>
          <span>性别:{{ item.sexs }}</span>
          <span>年龄:{{ item.age }}</span>
        </div>
      </div>
      <div class="info_flexl" style="margin-top: 10px">
        <span>手机号:{{ item.mobile }}</span>
        <span>地区:{{ item.address }}</span>
        <span>团队人数:{{ item.team }}</span>
        <span>升级后团队人数:{{ item.up_team }}</span>
      </div>
    </el-card>
// 加载树图
drewTree(a) {
  const myChart = echarts.init(document.getElementById('main'))
  myChart.setOption({
      tooltip:[],
      series:[]
  })
  // 阻止右键默认的菜单弹出
  document.oncontextmenu = function(param) {
    return false
  }
if (a) { // 存在右键点击
    this.$nextTick(() => {
       that.infoList.forEach((v, i, arr) => {
          const model = myChart.getModel().getSeriesByIndex(0).getData()._itemLayouts // 树形图所有节点坐标
            const info = document.getElementById('data' + i)
            info.style.display = 'block'
            info.style.left = model[v.l + 1].x + 10 + 'px'
            console.log(model[v.l + 1].y)
            if (model[v.l + 1].y < 150) {  // 节点位置太靠上,详情框显示不出来,定位到节点下方
              info.style.top = model[v.l + 1].y + 190 + 'px'
            } else {
              info.style.top = model[v.l + 1].y - 190 + 'px'
            }
         })
     })
  }
  myChart.on('contextmenu', this.rightClick) // 右键事件
},
// 右键事件
rightClick(param) {
  console.log(param) // 获取节点参数
const list = this.getParentId(this.datas, param.data.id)
      const arr = []
      list.forEach((item) => {
        if (item.name !== 'xx关系') {
          arr.push(Object.assign({}, { id: item.id, status: item.id !== param.data.id ? item.status : item.status ? 0 : 1 }))
        }
      })
      const that = this
      const myChart = echarts.init(document.getElementById('main'))
      axios
        .get('xxxxx', {
          params: {
            id: param.data.id,
            arr: arr.reverse()
          }})
        .then(res => {
          this.datas = [
            {
              'name': 'xx关系图',
              'id': 1,
              'children': eachKeyed(res.data.data.data)
            }
          ]
          myChart.clear()
          that.infoList = res.data.data.info[1]
          that.drewTree(that.datas, param.data.name, 1)
},
<style lang='scss' scoped>
.info {
  width: 240px;
  display: none;
  position: absolute;
  left: -99999px;
  top: -999999px;
  &_flex {
    display: flex;
    align-items: center;
  }
  &_flexl {
    display: flex;
    flex-direction: column;
  }
  &_img {
    width: 75px;
    height: 75px;
    margin-right: 10px;
    display: inline-block;
  }
  &_wid {
    span {
      display: inline-block;
      width: 135px;
      height: 19px;
      overflow: hidden;
    }
  }
}
</style>

相关文章

  • echarts 树图 右键操作,多个节点展示详情框

    效果:

  • DOM基本操作二

    事件代理操作: 添加节点操作: 节点属性操作: 轮播头图: 模态框基本功能:

  • echarts

    vue引入echarts 多个图图状显示

  • 网址记录之echarts

    饼图程序调用高亮示例 echarts节点折叠实现

  • Echarts

    柱形图 原文链接 Echarts学习tooltip提示框

  • Echarts tree结构使用

    需求:关系族谱图,多叉树结构展示 技术:Echarts tree结构 难点 控制节点的缩起和展开状态 同一个等级...

  • 数据结构4、树 Tree

    一、定义 树,实际上是图的一种。 树是由节点构成的数据结构: 每棵树都有一个根节点。 根节点有0个或多个子节点。 ...

  • 关系图的使用

    前言 此功能利用echarts的关系力图,达到节点和边的展示。请在读此文章前阅读echarts官方文档、echar...

  • Vue—Echarts 柱状图

    使用Vue做后台管理系统的时候避免不了使用Echarts来展示对应的数据,下面是使用Echarts柱状图来展示对应...

  • Echarts图表实现后台数据统计

    柱状图获取后台数据展示: 饼图获取后台数据展示: 前端实现方法: var myChart = echarts.in...

网友评论

      本文标题:echarts 树图 右键操作,多个节点展示详情框

      本文链接:https://www.haomeiwen.com/subject/qlowtdtx.html