鲜活数据的艺术:使用Vue和ECharts绘制交互式词云图的完整指南

       首先效果图

        1.你需要了解echarts的简单使用方法,以及各个配置项的作用。

        2.在下载echarts后还需要下载wordcloud

npm install echarts-wordcloud --save

        3.引入wordcloud(我的echarts是挂载到Vue原型上的,在此不需要再引入)

import 'echarts-wordcloud';

        4.主要代码(注意要给盒子容器ref=“wordCloud”属性,并给定宽高)

getChart() {
      this.worldCloudChart = this.$echarts.init(this.$refs.wordCloud);
      this.option = {
        tooltip: {
          show: true,
          position: "top",
          formatter: (params) => {
            return `${params.marker}${params.name} : 热度${params.value}`;
          },
          textStyle: {
            fontSize: 14,
          },
        },
        series: [
          {
            type: "wordCloud",
            // 网格大小,各项之间间距
            gridSize: 15,
            // 形状 circle 圆,cardioid  心, diamond 菱形,triangle-forward 、triangle 三角,star五角星
            shape: "circle",
            // 字体大小范围
            sizeRange: [16, 40],
            // 文字旋转角度范围
            rotationRange: [0, 50],
            // 旋转步值
            rotationStep: 40,
            left: "center",
            top: "center",
            right: null,
            bottom: null,
            // 画布的宽
            // width: "90%",
            // 画布的高
            // height: "90%",
            // 是否渲染超出画布的文字
            drawOutOfBound: false,
            textStyle: {
              normal: {
                color: function () {
                  return (
                    "rgb(" +
                    [
                      Math.round(Math.random() * 255),
                      Math.round(Math.random() * 255),
                      Math.round(Math.random() * 255),
                    ].join(",") +
                    ")"
                  );
                },
              },
              emphasis: {
                shadowBlur: 10,
                shadowColor: "#2ac",
              },
            },
            geo: {
              zoom: 1,
              scaleLimit: {
                min: 0.5,
                max: 2,
              },
            },
            data: [
              {
                name: "Hidden Cobra(Trend Micro)",
                value: 100,
              },
              { ...//数据自己加,value值越大,字体显示越大
               }
            ],
          },
        ],
      };
      this.wordCloudChart.setOption(this.option);
      window.onresize = this.wordCloudChart.resize;//自适应
}

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

前端奇遇记

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值