echarts词云图

echarts-wordcloud的git仓库地址
https://github.com/ecomfe/echarts-wordcloud

echarts官方文档
https://echarts.apache.org/zh/index.html

依赖版本号
“echarts”: “^5.0.1”,
“echarts-wordcloud”: “^2.0.0”,
版本号可以根据echarts-wordcloud依赖里面的版本号找到对应echarts的版本,否则很容易出现问题,echarts-wordcloud2.0 中使用textStyle 不可以加nomal 可以在上面的仓库里面看官方示例。
————————————————
版权声明:本文为CSDN博主「勿扰丶」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_46063007/article/details/120655150

// 封装成组件
<template>
  <div>
    <div id="chart" style="width: 500px; height: 400px"></div>
  </div>
</template>

<script>
import * as echarts from "echarts";
import "echarts-wordcloud";
// import "echarts-wordcloud/dist/echarts-wordcloud.min";
export default {
  data() {
    return {
      wordList: [
        {
          name: "珍珠奶茶",
          value: 15000,
        },
        {
          name: "冰激凌红茶",
          value: 10081,
        },
        {
          name: "椰果奶茶",
          value: 9386,
        },
        {
          name: "波霸奶茶",
          value: 7500,
        },
        {
          name: "金桔柠檬",
          value: 7500,
        },
        {
          name: "乌龙奶茶",
          value: 6500,
        },
        {
          name: "芒果欧蕾",
          value: 6500,
        },
        {
          name: "仙草奶茶",
          value: 6000,
        },
        {
          name: "翡翠柠檬",
          value: 4500,
        },
        {
          name: "芒果养乐多",
          value: 3800,
        },
        {
          name: "柠檬养乐多",
          value: 3000,
        },
        {
          name: "波霸奶绿",
          value: 2500,
        },
        {
          name: "四季春茶",
          value: 2300,
        },
        {
          name: "茉莉绿茶",
          value: 2000,
        },
        {
          name: "阿萨姆红茶",
          value: 1900,
        },
        {
          name: "奶冻摇摇乐",
          value: 1800,
        },
        {
          name: "冻顶乌龙茶",
          value: 1700,
        },
        {
          name: "咖啡",
          value: 1600,
        },
        {
          name: "焦糖玛奇朵",
          value: 1500,
        },
        {
          name: "金桔柠檬",
          value: 1200,
        },
      ],
    };
  },
  mounted() {
    this.initchart();
  },
  methods: {
    initchart() {
      let myChart = echarts.init(document.querySelector("#chart"));
      myChart.setOption({
        series: [
          {
            type: "wordCloud",
            //用来调整词之间的距离
            gridSize: 10,
            //用来调整字的大小范围
            // Text size range which the value in data will be mapped to.
            // Default to have minimum 12px and maximum 60px size.
            sizeRange: [14, 60],
            // Text rotation range and step in degree. Text will be rotated randomly in range [-90,                                                                             90] by rotationStep 45
            //用来调整词的旋转方向,,[0,0]--代表着没有角度,也就是词为水平方向,需要设置角度参考注释内容
            // rotationRange: [-45, 0, 45, 90],
            // rotationRange: [ 0,90],
            rotationRange: [0, 0],
            //随机生成字体颜色
            // maskImage: maskImage,
            textStyle: {
              color: function () {
                return (
                  "rgb(" +
                  Math.round(Math.random() * 255) +
                  ", " +
                  Math.round(Math.random() * 255) +
                  ", " +
                  Math.round(Math.random() * 255) +
                  ")"
                );
              },
            },
            //位置相关设置
            // Folllowing left/top/width/height/right/bottom are used for positioning the word cloud
            // Default to be put in the center and has 75% x 80% size.
            left: "center",
            top: "center",
            right: null,
            bottom: null,
            width: "200%",
            height: "200%",
            //数据
            data: this.wordList,
          },
        ],
      });
    },
  },
};
</script>


//页面中使用,引入组件并使用,宽高可以以当做参数做动态来写
    <wordcloud />

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Echarts 是一个非常流行的数据可视化库,它支持多种图表类型,包括词云图。下面是一个简单的使用 Echarts 绘制词云图的示例: ```html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Echarts 词云图</title> <!-- 引入 Echarts 库 --> <script src="https://cdn.jsdelivr.net/npm/echarts/dist/echarts.min.js"></script> </head> <body> <!-- 使用 Echarts 绘制词云图的容器 --> <div id="wordcloud" style="width: 600px; height: 400px;"></div> <script> // 基于准备好的dom,初始化echarts实例 var myChart = echarts.init(document.getElementById('wordcloud')); // 定义词云图的数据 var data = [ {name: '张三', value: 100}, {name: '李四', value: 80}, {name: '王五', value: 70}, {name: '赵六', value: 60}, {name: '钱七', value: 50}, {name: '孙八', value: 40}, {name: '周九', value: 30}, {name: '吴十', value: 20}, ]; // 配置词云图的参数 var option = { series: [{ type: 'wordCloud', shape: 'circle', left: 'center', top: 'center', width: '80%', height: '80%', right: null, bottom: null, sizeRange: [12, 60], rotationRange: [-90, 90], rotationStep: 45, gridSize: 8, drawOutOfBound: false, textStyle: { normal: { fontFamily: 'sans-serif', fontWeight: 'bold', color: function () { return 'rgb(' + [ Math.round(Math.random() * 160), Math.round(Math.random() * 160), Math.round(Math.random() * 160) ].join(',') + ')'; } }, emphasis: { shadowBlur: 10, shadowColor: '#333' } }, data: data }] }; // 使用刚指定的配置项和数据显示图表。 myChart.setOption(option); </script> </body> </html> ``` 这个示例中,我们首先引入了 Echarts 库,然后在页面中创建一个容器用于显示词云图。接着,我们定义了词云图的数据,包括每个词的名称和权重。最后,我们使用 Echarts 的 `wordCloud` 类型来创建词云图,并通过配置参数来指定词云图的样式和数据。最终,我们将配置项和数据传递给 Echarts 的实例对象,并通过调用 `setOption` 方法显示图表。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值