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);
})
模型图以及改后结果图

在这里插入图片描述

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在 Vue 中实现人物关系的展示和筛选,可以使用 ECharts 的数据过滤功能。具体步骤如下: 1. 安装 ECharts 和 Vue-ECharts 在项目中安装 ECharts 和 Vue-ECharts,可以使用 npm 安装: ``` npm install echarts vue-echarts ``` 2. 引入 ECharts 和 Vue-ECharts 在需要使用人物关系的组件中,引入 ECharts 和 Vue-ECharts: ```javascript import echarts from 'echarts' import VueECharts from 'vue-echarts' ``` 3. 定义数据 定义一个数组来存储人物关系的数据,每个元素为一个对象,包含节点的名称、类别、标签等信息,以及节点之间的关系: ```javascript const data = [ { name: '人物1', category: 0, itemStyle: { color: '#ff0000' } }, { name: '人物2', category: 1, itemStyle: { color: '#00ff00' } }, { name: '人物3', category: 1, itemStyle: { color: '#0000ff' } } ] const links = [ { source: '人物1', target: '人物2' }, { source: '人物2', target: '人物3' }, { source: '人物3', target: '人物1' } ] ``` 4. 渲染表 在模板中使用 Vue-ECharts 渲染表,使用 ECharts关系表类型,传入定义好的数据: ```html <template> <div> <div> <button @click="filter(0)">筛选类别1</button> <button @click="filter(1)">筛选类别2</button> <button @click="reset()">重置</button> </div> <vue-echarts ref="chart" :options="options"></vue-echarts> </div> </template> <script> import echarts from 'echarts' import VueECharts from 'vue-echarts' export default { components: { VueECharts }, data () { return { options: { title: { text: '人物关系' }, tooltip: {}, legend: { data: ['类别1', '类别2'] }, series: [ { type: 'graph', layout: 'force', data: data, links: links, roam: true, label: { show: true }, force: { repulsion: 100 } } ] } } }, methods: { filter (category) { const chart = this.$refs.chart.echarts chart.dispatchAction({ type: 'dataFilter', filterMode: 'weakFilter', // 过滤函数,返回 true 表示保留 filter: (dataIndex) => { return data[dataIndex].category === category } }) }, reset () { const chart = this.$refs.chart.echarts chart.dispatchAction({ type: 'dataFilter', filterMode: 'none' }) } } } </script> ``` 以上代码中,我们添加了三个按钮来进行筛选和重置操作。在 `filter` 方法中,我们使用 ECharts 的 `dispatchAction` 方法来触发数据过滤行为。在 `reset` 方法中,我们将过滤模式设置为 `none`,即取消所有过滤。 注意,为了使数据过滤生效,需要将 ECharts 实例的引用存储在组件中,这里使用了 Vue 的 `ref` 属性来引用 ECharts 组件,并在 `filter` 和 `reset` 方法中通过 `$refs` 属性获取 ECharts 实例。 以上就是使用 Vue 和 ECharts 实现人物关系展示和筛选的基本步骤,根据实际需求可以进一步调整和定制表的样式和交互行为。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值