Vue使用echarts-wordcloud生成词云

介绍

Echarts词云控件,可方便的对词组进行可视化的显示。

源码工程地址:WordCloud

效果图

Vue使用echarts-wordcloud生成词云_第1张图片

安装

npm install echarts
npm install echarts-wordcloud

使用方式

let echarts = require('echarts/lib/echarts')
require('echarts-wordcloud');
import 'echarts/theme/macarons.js'

export default {
  name: 'word_cloud_index',
  data: () => ({
    word_cloud_view: null,
    word_cloud_options: {},
    word_list: [{"name": "需求", "value": 10927}, {"name": "修改", "value": 5902}]
  }),
  methods: {
    draw_word_cloud_view() {
      if (this.word_cloud_view) {
        this.word_cloud_view.dispose();
      }
      this.word_cloud_view = document.getElementById('word_cloud_view_id') && echarts.init(document.getElementById('word_cloud_view_id'), 'macarons');
      this.word_cloud_view && this.word_cloud_view.setOption(this.word_cloud_options);
    },
    init_view_data() {
      let word_cloud_series = [{
        type: 'wordCloud',
        shape: 'circle',
        //maskImage: maskImage,
        left: 'center',
        top: 'center',
        width: '100%',
        height: '100%',
        right: null,
        bottom: null,
        sizeRange: [6, 60],
        rotationRange: [-45, 90],
        autoSize: {
          enable: true,
          minSize: 6
        },
        textPadding: 0,
        // rotationStep: 45,
        // gridSize: 8,
        drawOutOfBound: false,
        textStyle: {
          normal: {
            fontFamily: 'sans-serif',
            fontWeight: 'bold',
            // Color can be a callback function or a color string
            color: function () {
              // Random color
              return 'rgb(' + [
                Math.round(Math.random() * 256),
                Math.round(Math.random() * 256),
                Math.round(Math.random() * 256)
              ].join(',') + ')';
            }
          },
          emphasis: {
            shadowBlur: 10,
            shadowColor: '#333'
          }
        },
        data: this.word_list
      }]

      this.word_cloud_options = {
        series: word_cloud_series
      }
      this.word_cloud_view.setOption(this.word_cloud_options)
    },
  },
  mounted() {
    this.draw_word_cloud_view()
    this.init_view_data()
  },
  render(h) {
    return h('div', {
      attrs: {id: 'word_cloud_view_id'},
      style: {
        height: '400px',
        width: '400px'
      }
    })
  }
}

参数说明

参数 说明 类型 可选值 默认值

插件地址:echarts-wordcloud

你可能感兴趣的:(#,Vue)