echarts关系图改造+color自定义

echats节点设置不同颜色
this.$nextTick(()=>{
  var chartDom = document.getElementById('echartshow');
  var myChart = echarts.init(chartDom);
  var option;
  option = {
    tooltip: {},
    animationDurationUpdate: 1500,
    animationEasingUpdate: 'quinticInOut',
    series: [
      {
        type: 'graph',
        layout: 'none',
        symbolSize: [60,25],//节点宽高
        symbolOffset:[10,0],//(箭头偏移)发现改为矩形并设置宽高后,遮盖了部分箭头,以此来消除影响
        roam: true,
        label: {
          show: true
        },
        symbol:'rect',//节点形状矩形。其他枚举:circle,rect,roundRect,triangle,diamond,pin,arrow,none
        edgeSymbol: ['circle', 'arrow'],//箭头形状 
        edgeSymbolSize: [2, 6],//箭头两端图尺寸
        edgeLabel: {
          fontSize: 20
        },
        itemStyle: {
          shadowBlur: 9,
          shadowOffsetX: 1.5,
          shadowOffsetY: 3,
          shadowColor: '#555',
          normal:{//不同节点显示不同颜色
            color: function(params) {
              return params.data.colors    //获取具体的参数
            },
          }
        },
        data: [
          {
            name: 'Node 1',
            x: 300,
            y: 300,
            colors:'#333'
          },
          {
            name: 'Node 2',
            x: 650,
            y: 300,
            colors:'#600'
          },
          {
            name: 'Node 5',
            x: 650,
            y: 400,
            colors:'#897'
          },
          {
            name: 'Node 6',
            x: 650,
            y: 500,
            colors:'#004'
          },
          {
            name: 'Node 7',
            x: 950,
            y: 300,
            colors:'#234'
          },
          {
            name: 'Node 8',
            x: 1200,
            y: 300,
            colors:'#520'
          },
        ],
        links: [
          {
            source: 'Node 1',
            target: 'Node 2',
          },
          {
            source: 'Node 2',
            target: 'Node 7',
          },
          {
            source: 'Node 5',
            target: 'Node 7'
          },
          {
            source: 'Node 6',
            target: 'Node 7'
          },
          {
            source: 'Node 7',
            target: 'Node 8'
          }
        ],
        lineStyle: {//箭头线条透明度、宽度以及弯曲度
          opacity: 0.9,
          width: 2,
          curveness: 0
        }
      }
    ]
  };
  option && myChart.setOption(option);
})
模型图以及改后结果图

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值