Vue 绘制echarts 词云和 Highcharts 词云

echarts绘制词云方法

echarts官网

  • 第一步安装echarts依赖,通过npm获取echarts,npm install echarts --save,具体操作可以看echarts官网;
  • 第二步安装echarts词云插件,npm install echarts-wordcloud --save;
  • 第三步下载好依赖之后在main.js引入文件,我这里最后将echarts写在原型prototype上
  import echarts from 'echarts'
  require('echarts-wordcloud')
  Vue.prototype.$echarts = echarts
  • 第四步绘制词云
  <template>
    <div id="echartsWordcloud" style="width:400px;height:400px;"></div>
  </template>
  <script>
  export default{
    mounted(){
      this.initEcharts()
    },
    methods:{
      initEcharts(data){
          let echartsWordcloud=this.$echarts.init(document.getElementById("echartsWordcloud"));
          let option = {
            title: {
              text: "",
              x: "center"
            },
            series: [
              {
                type: "wordCloud",
                //用来调整词之间的距离
                gridSize: 10,
                //用来调整字的大小范围
                sizeRange: [14, 26],
                rotationRange: [0, 0],
                //随机生成字体颜色
                textStyle: {
                  normal: {
                    color: function() {
                      return (
                        "rgb(" +
                        Math.round(Math.random() * 255) +
                        ", " +
                        Math.round(Math.random() * 255) +
                        ", " +
                        Math.round(Math.random() * 255) +
                        ")"
                      );
                    }
                  }
                },
                //位置相关设置
                left: "center",
                top: "center",
                right: null,
                bottom: null,
                width: "300%",
                height: "300%",
                //数据
                data: data
              }
            ]
          };
          echartsWordcloud.setOption(option);
          //点击事件
          echartsWordcloud.on("click",function(e){})
      }
    }
  }
  </script>

效果图

Highcharts绘制词云方法

Highcharts官网
第一步下载highcharts,可以选择文件下载方式和npm安装方式(npm install highcharts --save),官网都有教程,我选择是文件下载方式。
第二步引入highcharts文件

  <script src="./lib/highcharts/highcharts.js"></script>
  <script src="./lib/highcharts/wordcloud.js"></script>

第三步绘制词云

  <template>
    <div id="highchartsWordcloud" style="width:400px;height:400px;"></div>
  </template>
  <script>
  export default{
    mounted(){
      this.initEcharts()
    },
    methods:{
      initEcharts(data){
         Highcharts.chart("highchartsWordcloud", {
           colors: ["#6A7AFE", "#9DBBEC", "#FFDB35", "#FFFFFF"],
           tooltip: {
             enabled: false
           },
           chart: {
             plotBackgroundColor: null,
             backgroundColor: null
           },
           title: {
             text: null
             // fontWeight: "400"
           },
           credits: {
             enabled: false // 禁用版权信息
           },
           exporting:{enabled:false},
           series: [
             {
               type: "wordcloud",
               data: data,
               cursor: "pointer",
               rotation: {
                 from: 0,
                 to: 0,
                 orientations: 5
               },
              //点击事件
               events: {
                 click: function(e) {}
               }
             }
           ]
         });
      }
    }
  }
  </script>

效果图

渲染数据格式举例

data = [{name: "小区",value: "283"},{name: "留言板",value: "101"},...,{name: "业主",value: "148"}]
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值