VUE实现echarts(悲惨世界人物关系图示例)

1.引入echarts

npm i echarts

2.main.js中导入

import * as echarts from 'echarts'
Vue.prototype.$echarts = echarts

3.https://cdn.jsdelivr.net/gh/apache/echarts-website@asf-site/examples/data/asset/data/les-miserables.json,下载echarts的图表数据(json文件),放入components文件下,以备导入

4.导入json文件,并做以下配置

import root from '@/components/les-miserables.json'


mounted() {
    this.setecharts()
  },
methods: {
    setecharts() {
      let myChart = this.$echarts.init(document.getElementById('box'))
      var option
      myChart.showLoading()
      JSON.stringify(root, function () {
        console.log(root)
        myChart.hideLoading()
        root.nodes.forEach(function (node) {
          node.label = {
            show: node.symbolSize > 30,
          }
        })
        option = {
          title: {
            text: 'Les Miserables',
            subtext: 'Circular layout',
            top: 'bottom',
            left: 'right',
          },
          tooltip: {},
          legend: [
            {
              data: root.categories.map(function (a) {
                return a.name
              }),
            },
          ],
          animationDurationUpdate: 1500,
          animationEasingUpdate: 'quinticInOut',
          series: [
            {
              name: 'Les Miserables',
              type: 'graph',
              focusNodeAdjacency: true, //当鼠标移动到节点上,突出显示节点以及节点的边和邻接节点
              layout: 'circular',
              circular: {
                rotateLabel: true,
              },
              data: root.nodes,
              links: root.links,
              categories: root.categories,
              roam: true,
              label: {
                position: 'right',
                formatter: '{b}',
              },
              lineStyle: {
                color: 'source',
                curveness: 0.3,
                opacity: 1,
                width: 1.2,
              },
            },
          ],
        }
        myChart.setOption(option)
      })
    },
  },

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要展示人物关系,可以使用 VueECharts 结合起来实现。具体步骤如下: 1. 安装 EChartsVue-ECharts 在项目中安装 EChartsVue-ECharts,可以使用 npm 安装: ``` npm install echarts vue-echarts ``` 2. 引入 EChartsVue-ECharts 在需要使用人物关系的组件中,引入 EChartsVue-ECharts: ```javascript import echarts from 'echarts' import VueECharts from 'vue-echarts' ``` 3. 定义数据 定义一个数组来存储人物关系的数据,每个元素为一个对象,包含节点的名称、类别、标签等信息,以及节点之间的关系: ```javascript const data = [ { name: '人物1', itemStyle: { color: '#ff0000' } }, { name: '人物2', itemStyle: { color: '#00ff00' } }, { name: '人物3', itemStyle: { color: '#0000ff' } } ] const links = [ { source: '人物1', target: '人物2' }, { source: '人物2', target: '人物3' }, { source: '人物3', target: '人物1' } ] ``` 4. 渲染表 在模板中使用 Vue-ECharts 渲染表,使用 ECharts关系表类型,传入定义好的数据: ```html <template> <div> <vue-echarts :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: {}, series: [ { type: 'graph', layout: 'force', data: data, links: links, roam: true, label: { show: true }, force: { repulsion: 100 } } ] } } } } </script> ``` 以上就是使用 VueECharts 展示人物关系的基本步骤,根据实际需求可以进一步调整和定制表的样式和交互行为。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值