【开发日记】自己造的词云图可视化轮子

1、开发环境

测试环境是Vue2、ECharts5.4.1

2、安装ECharts

npm install echarts

3、安装echarts-wordcloud

npm install echarts-wordcloud

4、词云图Vue组件

<script>
/**
 * 词云图
 * 使用前请使用 npm install echarts-wordcloud 安装依赖
 * [{name:'',value:''}]
 */
import * as echarts from 'echarts';
import "echarts-wordcloud/dist/echarts-wordcloud";
import "echarts-wordcloud/dist/echarts-wordcloud.min";
export default {
    name: "WordChart",
    props: {
        data: {
            type: Array,
            required: true
        }
    },
    mounted() {
        const chart = echarts.init(this.$refs.wordChart);
        const option = {
            title: {
                text: "词云图",
                x: "left",
            },
            backgroundColor: "#fff",
            series: [
                {
                    type: "wordCloud",
                    //用来调整词之间的距离
                    gridSize: 10,
                    //用来调整字的大小范围
                    sizeRange: [14, 60],
                    //用来调整词的旋转方向,,[0,0]--代表着没有角度,也就是词为水平方向,需要设置角度参考注释内容
                    // rotationRange: [-45, 0, 45, 90],
                    // rotationRange: [ 0,90],
                    rotationRange: [0, 0],
                    //随机生成字体颜色
                    textStyle: {
                        normal: {
                            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.data,
                },
            ],
        };
        option && chart.setOption(option);
    }
}
</script>

<template>
    <div ref="wordChart" style="width: 800px; height: 400px;"></div>
</template>
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

二饭

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

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

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

打赏作者

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

抵扣说明:

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

余额充值