echarts 气泡文字云

1. 代码

<template>
  <div :id="id" :ref="id" class="main"></div>
</template>
  <script>
import * as echarts from "echarts";
export default {
  name: "radar",
  data() {
    return {
      myEchart: null
    };
  },
  props: {
    id: {
      type: String,
      default: "mainId1"
    }
  },
  watch: {
    indicatorList: {
      handler(newName, oldName) {
        this.$nextTick(() => {
          this.drawChart();
          window.addEventListener("resize", this.drawChart);
        });
      },
      deep: true
    }
  },
  destroyed() {
    window.removeEventListener("resize", this.drawChart);
  },
  methods: {
    drawChart() {
      let that = this;
      let timer = null;
      timer = setTimeout(() => {
        if (
          this.myEchart != null &&
          this.myEchart != "" &&
          this.myEchart != undefined
        ) {
          this.myEchart.dispose(); //销毁
        }
        if (!this.$refs[this.id]) return;
        that.myEchart = this.$echarts.init(this.$refs[this.id]);
        let option = {
          series: [
            {
              type: "graph",
              layout: "force",
              legendHoverLink: false,
              force: {
                repulsion: 160,
                edgeLength: 70
              },
              categories: [
                {
                  itemStyle: {
                    color: "#409EFF"
                  }
                },
                {
                  itemStyle: {
                    color: "#67C23A"
                  }
                },
                {
                  itemStyle: {
                    color: "#E6A23C"
                  }
                },
                {
                  itemStyle: {
                    color: "#F56C6C"
                  }
                },
                {
                  itemStyle: {
                    color: "#ff7edb"
                  }
                }
              ],
              label: {
                normal: {
                  show: true
                }
              },
              data: [
                {
                  category: 3,
                  label: { fontSize: 23 },
                  name: "15",
                  symbolSize: 42.5,
                  value: 15
                },
                {
                  category: 1,
                  label: { fontSize: 23 },
                  name: "14",
                  symbolSize: 42.5,
                  value: 3
                },
                {
                  category: 2,
                  label: { fontSize: 23 },
                  name: "30",
                  symbolSize: 42.5,
                  value: 300
                }
              ]
            }
          ]
        };
        this.myEchart.setOption(option);
      }, 500);
    }
  },
  mounted() {
    this.drawChart();
  }
};
</script>
  <style lang="scss" scoped>
.main {
  width: 100%;
  height: 100%;
}
</style>
  

2. 说明

(1)name不能相同,不然会报错

(2)category不同,颜色就不同

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值