echarts词云图(echarts版本 5.3.3)

<template>
  <div class="cont">

    <div ref="chart" :style="{width: '100%', height: '2.3rem'}"></div>

  </div>
</template>

<script>
import { getlargeScreen } from '@/service/index'
import wordcloud from 'echarts-wordcloud'
export default {
  components: {

  },
  props: {
    tabActive: {
      type: String,
      default: () => ''
    },
    realTimeData: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {

      chartInstance: null,


      cockpitData: [
        {
          "unit": "个",
          "areaname": "沈阳",
          "time": "2021-08-30 15:38:00",
          "title": "各地市水源数",
          "value": "0"
        },
        {
          "unit": "个",
          "areaname": "大连",
          "time": "2021-08-30 15:38:00",
          "title": "各地市水源数",
          "value": "3"
        },
        {
          "unit": "个",
          "areaname": "鞍山",
          "time": "2021-08-30 15:38:00",
          "title": "各地市水源数",
          "value": "0"
        },
        {
          "unit": "个",
          "areaname": "抚顺",
          "time": "2021-08-30 15:38:00",
          "title": "各地市水源数",
          "value": "2"
        },
        {
          "unit": "个",
          "areaname": "本溪",
          "time": "2021-08-30 15:38:00",
          "title": "各地市水源数",
          "value": "3"
        },
        {
          "unit": "个",
          "areaname": "丹东",
          "time": "2021-08-30 15:38:00",
          "title": "各地市水源数",
          "value": "8"
        },
        {
          "unit": "个",
          "areaname": "锦州",
          "time": "2021-08-30 15:38:00",
          "title": "各地市水源数",
          "value": "1"
        },
        {
          "unit": "个",
          "areaname": "营口",
          "time": "2021-08-30 15:38:00",
          "title": "各地市水源数",
          "value": "4"
        },
        {
          "unit": "个",
          "areaname": "阜新",
          "time": "2021-08-30 15:38:00",
          "title": "各地市水源数",
          "value": "1"
        },
        {
          "unit": "个",
          "areaname": "辽阳",
          "time": "2021-08-30 15:38:00",
          "title": "各地市水源数",
          "value": "1"
        },
        {
          "unit": "个",
          "areaname": "盘锦",
          "time": "2021-08-30 15:38:00",
          "title": "各地市水源数",
          "value": "0"
        },
      ],
    }
  },
  watch: {
    tabActive(val) {
      console.log('值2', val);
      this.areacodel = val
      this.getlargeScreen()
    },
    deep: true
  },
  methods: {
    open() {
      // setTimeout(() => {
      //   this.drawLine()

      // }, 500);
      this.$nextTick(() => {
        //  执行echarts方法
        this.drawLine()

      })
    },

    //  图表初始化
    drawLine() {
      // 基于准备好的dom,初始化echarts实例
      this.statusChart = this.$echarts.init(this.$refs.chart)
      // 绘制图表
      this.statusChart.setOption({
        title: {
          text: '',
          x: 'center',
          textStyle: {
            fontSize: 23
          }

        },
        backgroundColor: '',
        tooltip: {
          show: false
        },
        toolbox: {
          feature: {

          }
        },
        series: [{
          name: '',
          type: 'wordCloud',
          //size: ['9%', '99%'],
          sizeRange: [6, 66],
          //textRotation: [0, 45, 90, -45],
          rotationRange: [-45, 90],
          //shape: 'circle',
          textPadding: 0,
          autoSize: {
            enable: true,
            minSize: 6
          },
          textStyle: {
            fontFamily: '微软雅黑',
            color: function () {
              return 'rgb(' + [
                Math.round(Math.random() * 160),
                Math.round(Math.random() * 150),
                Math.round(Math.random() * 130)
              ].join(',') + ')';
            },

            emphasis: {
              shadowBlur: 20,
              shadowColor: '#333'
            }
          },
          data: this.cockpitData
        }]
      });

    },
    async getlargeScreen() {
      var sw = await getlargeScreen({
        areacodel: this.areacodel
      })
      console.log(2222222, sw);
      this.list = sw.result
    },

  },
  created() {
    this.$emit('changeCity', this.city)
    // this.getData1()
    this.getlargeScreen()
    let lists = [];
    for (let i = 0; i < this.cockpitData.length; i++) {
      let res = JSON.parse(
        JSON.stringify(this.cockpitData[i])
          .replace(/areaname/g, 'name')
      );
      lists.push(res);
    }
    console.log(111, lists)
    this.cockpitData = lists
  },
  mounted() {
    this.$nextTick(function () {
      this.drawLine()
    })
    //根据窗口变化自动调节图表大小


  },
  beforeDestroy() {
    // 页面组件销毁,移除echart自适应事件
    window.removeEventListener("resize", () => {
      this.chartInstance.resize()
    })
  }
}
</script>

<style lang="scss"  scoped>
//弹出层
</style>

词云图依赖

npm install echarts-wordcloud

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值