首页 > 其他分享 >vue echarts graph 关系图

vue echarts graph 关系图

时间:2022-10-30 16:16:03浏览次数:48  
标签:vue name color graph source fieldName fieldLevel echarts target

最近项目需要,用到了echart 的grpah关系图,研究了下,大概就画个简单的吧

html:

<div id="app">
     <div
         id="main"
         class="echarts"
         :style="{ width: '1600px', height: '700px' }"
     ></div>
</div>

 

js:

var app = new Vue({
       el: "#app",
       name: "app",
       data() {
         return {
           data: [
             {
               x: 200,
               y: 200,
               symbolSize: 100,
               imgUrl: "http://pic.imeitou.com/uploads/allimg/2016070119/z01mim54az1.jpg",
               draggable: true,
               name: "董事长",
               fieldName: "马云",
               fieldLevel: "阿里巴巴",
               itemStyle: {
                 normal: {
                   shadowBlur: 20,
                   shadowColor: "skyblue",
                   color: "skyblue"
                 }
               }
             },
             {
               x: 230,
               y: 350,
               name: "副总裁1",
               fieldName: "李逸",
               fieldLevel: "上下级",
               symbolSize: 80,
               imgUrl: "https://img2.woyaogexing.com/2022/10/29/b789b32cead4e3b7!400x400.jpg",
               itemStyle: {
                 normal: {
                   shadowBlur: 20,
                   shadowColor: "#AED6F1",
                   color: "#AED6F1"
                 }
               }
             },
             {
               x: 270,
               y: 220,
               name: "副总裁2",
               fieldName: "李虎",
               fieldLevel: "上下级",
               symbolSize: 80,
               imgUrl: "https://img2.woyaogexing.com/2022/10/29/26687cac3728e329!400x400.jpg",
               itemStyle: {
                 normal: {
                   shadowBlur: 20,
                   shadowColor: "#AED6F1",
                   color: "#AED6F1"
                 }
               }
             },
             {
               x: 120,
               y: 140,
               name: "副总裁3",
               fieldName: "赵四",
               fieldLevel: "同级",
               symbolSize: 80,
               imgUrl: "https://img2.woyaogexing.com/2022/10/29/e5d46fc68536e579!400x400.jpg",
               itemStyle: {
                 normal: {
                   shadowBlur: 20,
                   shadowColor: "#AED6F1",
                   color: "#AED6F1"
                 }
               }
             },
             {
               x: 140,
               y: 330,
               name: "副总裁4",
               fieldName: "周十",
               fieldLevel: "上下级",
               symbolSize: 80,
               imgUrl: "https://img2.woyaogexing.com/2022/10/29/c3219bd2ebbacc76!400x400.jpg",
               itemStyle: {
                 normal: {
                   shadowBlur: 20,
                   shadowColor: "#AED6F1",
                   color: "#AED6F1"
                 }
               }
             },
             {
               x: 70,
               y: 220,
               name: "副总裁5",
               fieldName: "钱三",
               fieldLevel: "上下级",
               symbolSize: 80,
               imgUrl: "https://img2.woyaogexing.com/2022/10/29/085101c84d057bd9!400x400.jpg",
               itemStyle: {
                 normal: {
                   shadowBlur: 20,
                   shadowColor: "#AED6F1",
                   color: "#AED6F1"
                 }
               }
             },
             {
               x: 80,
               y: 300,
               name: "副总裁6",
               fieldName: "吴三桂",
               fieldLevel: "上下级",
               symbolSize: 80,
               imgUrl: "https://img2.woyaogexing.com/2022/10/29/4d0adfeccc148efe!400x400.jpg",
               itemStyle: {
                 normal: {
                   shadowBlur: 20,
                   shadowColor: "#AED6F1",
                   color: "#AED6F1"
                 }
               }
             },
             {
               x: 300,
               y: 320,
               name: "副总裁7",
               fieldName: "郑六",
               fieldLevel: "上下级",
               symbolSize: 80,
               imgUrl: "https://img2.woyaogexing.com/2022/10/29/a4c352d717e1c5ea!400x400.jpg",
               itemStyle: {
                 normal: {
                   shadowBlur: 20,
                   shadowColor: "#AED6F1",
                   color: "#AED6F1"
                 }
               }
             },
             {
               x: 320,
               y: 250,
               name: "董事长助理",
               fieldName: "谭二三",
               fieldLevel: "上下级",
               symbolSize: 80,
               imgUrl: "https://img2.woyaogexing.com/2022/10/29/aaed8b0b8546c7df!400x400.jpg",
               itemStyle: {
                 normal: {
                   shadowBlur: 20,
                   shadowColor: "#AED6F1",
                   color: "#AED6F1"
                 }
               }
             },
             {
               x: 190,
               y: 280,
               name: "董事长顾问",
               fieldName: "许世友",
               fieldLevel: "上下级",
               symbolSize: 80,
               imgUrl: "https://img2.woyaogexing.com/2022/10/29/7188e0200aa7098c!400x400.png",
               itemStyle: {
                 normal: {
                   shadowBlur: 20,
                   shadowColor: "#AED6F1",
                   color: "#AED6F1"
                 }
               }
             },
             {
               x: 250,
               y: 280,
               name: "总裁办公室",
               fieldName: "曹蛮",
               fieldLevel: "上下级",
               symbolSize: 60,
               imgUrl: "https://img2.woyaogexing.com/2022/10/29/d78828899673f74b!400x400.jpg",
               itemStyle: {
                 normal: {
                   shadowBlur: 20,
                   shadowColor: "#BB8FCE",
                   color: "#BB8FCE "
                 }
               }
             },
             {
               x: 150,
               y: 250,
               name: "财务中心",
               fieldName: "孙尼",
               fieldLevel: "上下级",
               symbolSize: 60,
               imgUrl: "https://img2.woyaogexing.com/2022/10/29/2c5ba57512d87f9b!400x400.jpg",
               itemStyle: {
                 normal: {
                   shadowBlur: 20,
                   shadowColor: "#BB8FCE",
                   color: "#BB8FCE "
                 }
               }
             },
             {
               x: 280,
               y: 160,
               name: "行政中心",
               fieldName: "王一",
               fieldLevel: "上下级",
               symbolSize: 60,
               imgUrl: "https://img2.woyaogexing.com/2022/10/29/b2fe2473b799e806!400x400.jpg",
               itemStyle: {
                 normal: {
                   shadowBlur: 20,
                   shadowColor: "#BB8FCE",
                   color: "#BB8FCE "
                 }
               }
             },
             {
               x: 240,
               y: 180,
               name: "行政部门",
               fieldName: "李二",
               fieldLevel: "上下级",
               symbolSize: 50,
               imgUrl: "https://img2.woyaogexing.com/2022/10/29/ac490f447e1047f2!400x400.jpg",
               itemStyle: {
                 normal: {
                   shadowBlur: 20,
                   shadowColor: "#D35400",
                   color: "#D35400"
                 }
               }
             },
             {
               x: 140,
               y: 190,
               name: "财务部门",
               fieldName: "孙二一",
               fieldLevel: "上下级",
               symbolSize: 50,
               imgUrl: "https://img2.woyaogexing.com/2022/10/29/8bcce76f6ef9fac4!400x400.jpg",
               itemStyle: {
                 normal: {
                   shadowBlur: 20,
                   shadowColor: "#D35400",
                   color: "#D35400"
                 }
               }
             },
             {
               x: 140,
               y: 290,
               name: "人事部门",
               fieldName: "黄逸仁",
               fieldLevel: "上下级",
               symbolSize: 50,
               imgUrl: "https://img2.woyaogexing.com/2022/10/29/f28d422948eeb4af!400x400.jpg",
               itemStyle: {
                 normal: {
                   shadowBlur: 20,
                   shadowColor: "#D35400",
                   color: "#D35400"
                 }
               }
             },
             {
               x: 290,
               y: 290,
               name: "助理部门",
               fieldName: "马三",
               fieldLevel: "上下级",
               symbolSize: 50,
               imgUrl: "https://img2.woyaogexing.com/2022/10/29/cf1b3cbc4005d8be!400x400.jpg",
               itemStyle: {
                 normal: {
                   shadowBlur: 20,
                   shadowColor: "#D35400",
                   color: "#D35400"
                 }
               }
             },
           ],
           links: [
             {
               source: "董事长",
               target: "副总裁1",
             },
             {
               source: "董事长",
               target: "副总裁2",
             },
             {
               source: "董事长",
               target: "副总裁3",
             },
             {
               source: "副总裁2",
               target: "行政中心",
             },
             {
               source: "董事长",
               target: "副总裁4",
             },
             {
               source: "董事长",
               target: "副总裁5",
             },
             {
               source: "董事长",
               target: "董事长顾问",
             },
             {
               source: "董事长顾问",
               target: "总裁办公室",
             },
             {
               source: "董事长",
               target: "副总裁6",
             },
             {
               source: "副总裁5",
               target: "副总裁3",
             },
             {
               source: "董事长",
               target: "副总裁7",
             },
             {
               source: "董事长",
               target: "董事长助理",
             },
             {
               source: "董事长助理",
               target: "助理部门",
             },
             {
               source: "副总裁2",
               target: "行政中心",
             },
             {
               source: "副总裁5",
               target: "财务中心",
             },
             {
               source: "财务中心",
               target: "财务部门",
             },
             {
               source: "副总裁1",
               target: "人事部门",
             },
             {
               source: "副总裁3",
               target: "行政中心",
             },
             {
               source: "行政中心",
               target: "行政部门",
             },
           ],
         }
       },
       mounted: function () {
         var self = this;
         var chartDom = document.getElementById('main');
         var myChart = echarts.init(chartDom);
         myChart.showLoading();
         setTimeout(function () {
           myChart.hideLoading();
           var option = {
             title: {
               text: "Basic Graph",
             },
             tooltip: {
               formatter:self.formatterHover
             },
             animationDurationUpdate: 1500,
             animationEasingUpdate: "quinticInOut",
             series: [
               {
                 type: "graph",
                 layout: "none",
                 symbolSize: 50,
                 roam: true,
                 label: {  // 节点
                   show: true,
                   color: "#fff"
                 },
                 edgeSymbol: ["circle", "arrow"],
                 edgeSymbolSize: [6, 8], // 箭头大小
                 edgeLabel: {
                   show: true,
                   fontSize: 10,
                 },
                 data: self.data, //  数据
                 links: self.links, // 来源、目标
                 lineStyle: { // 线条属性
                   opacity: 0.3,
                   width: 1,
                   curveness: 0.3,
                   color: 'source',
                 },
                 emphasis: { // 鼠标悬停
                   focus: 'adjacency',
                   lineStyle: {
                     width: 10
                   }
                 }
               },
             ],
           };
           option && myChart.setOption(option);
         },2000);
       },
       methods: {
         //提示框信息
         formatterHover: function (params) {
           if (params.dataType == "node") {
             console.log(params);
             var deviceType = params.data.type;
             var imgPath = params.data.imgUrl;
             return "<div style='text-align: center'>" +
               "<img src='"+imgPath+" ' width='50px' height='50px' style='border-radius: 50%; -webkit-border-radius: 50%;'><br>" +
               '<span style="padding:0 5px;font-size: 13px;">'+ params.data.name+'</span><br>' +
               '<span style="padding:0 5px;font-size: 13px;">'+ params.data.fieldName+'</span><br>' +
               '<span style="padding:0 5px;font-size: 13px;">('+ params.data.fieldLevel+')</span></div>'
           }
         }
       }
 })

实现效果:

 

标签:vue,name,color,graph,source,fieldName,fieldLevel,echarts,target
From: https://www.cnblogs.com/tangjianqiang/p/16841471.html

相关文章

  • vue学习笔记
    今日内容概要计算属性监听属性组件介绍和定义父子通信之父传子父子通信之子传父ref属性动态组件插槽vue-cli今日内容详细计算属性我们可以通过计算属性c......
  • vue3路由的使用
    一、路由的概要1.1、什么是路由?路由就是一组映射关系,根据不同的url地址展示不同的内容或页面(key-value);key为路径,value可能是function或component 路......
  • Vue学习-04
    一、计算属性如果是{{}},每次页面刷新,函数都会重新执行写在computed的函数——当属性来使用,缓存通过计算属性实现名字首字母大写第一种:函数简单写法<!--大段的代码写在......
  • Vue学习笔记之使用computed计算属性
    Vuecomputed0x00概述本文主要记录Vue页面使用computed计算属性0x01computed基本使用在computed中定义一个函数(看起来是一个函数,其实是一个属性),命......
  • Vue学习笔记之Vue判断字符串(或数组)中是否包含某个元素
    Vue判断包含0x00概述Vue判断​​字符串​​中是否包含某个字符串,有如下方法。 0x01includes方法(数组,字符串都可以)varstr=“HelloWorld!”......
  • Vue学习笔记之el-date-picker组建时间格式化方式
    <el-date-pickersize="small"v-model="editData.startTime"type="datetime"placeholder="选择日期时间"value-format="yyyy-MM-ddHH:mm:ss"format="yyyy-MM-ddHH:mm......
  • Vue学习笔记之vue.js 两个等号 == 和三个等号===的区别 数字0和空字符串
    vuejavascript等号=====数字0空字符串/**==用于比较两者是否相等,忽略数据类型===用于更严谨的比较,值和值的数据类型都需要同时比较*/<!DOCT......
  • Vue学习笔记之loading
    1、在提交按钮上加入         :loading="loading"(注意前面有冒号)2、在return下加入          loading: false,先声明一下3、在刚进......
  • Vue学习笔记之Element-UI表单校验中的多层嵌套处理
    VUErules多层嵌套0x00概述本文主要记录VUE页面Element-UI表单校验中的多层嵌套处理。 0x01Element-UI表单校验中多层嵌套<el-row:gutter=20c......
  • 如何从零开发Vue,vue环境安装。
    1.首先去官网下载安装包​​https://nodejs.org/en/​​2.安装下载包。直接下一步下一步就行了。我这里安装在了D盘    D:\ProgramFiles\nodejs这个目录3.进入安......