• echarts5.x 词云图使用(`[ECharts] Unkown series wordCloud`)


    echarts5.x 词云图使用([ECharts] Unkown series wordCloud

    背景

    起先还庆幸自己 echarts 用的是 5.x 的版本,似乎可以少些麻烦

    结果发现按照 echarts-wordcloud 描述的操作歩鄹,词云图并出不来……

    打开控制台,出现了报错:log.js:62 [ECharts] Unkown series wordCloud

    估摸着就是引用不对,翻了几遍文档及网上的案例,都是那么简单的几步,并没有找到什么遗漏的操作

    没有办法,就试着看看是不是引用有问题,我找了下 node_modules 目录,发现并没有 wordCloud 相关的包,居然引用也不报错?打印出来发现 undefined,找不到返回 undefined 似乎逻辑上也没什么问题……

    没装上就重新装一下咯,结果发现 cnpm install echarts-wordcloud 秒过,但依赖包并没有下载过来,npm install echarts-wordcloud 等了半天装了一堆毫不相干的东西,还报了个错……


    装不上……那就复制源码本地保存一份咯……

    去到 echarts-wordcloud 的 github,复制了 echarts-wordcloud.min.js 代码,存在了 utils 目录下,然后用相对路径引入进来,发现就行了……

    预期效果

    请添加图片描述

    样例代码

    import * as echarts from "echarts"
    import "@/utils/echarts-wordcloud.min.js"
    
    drawLine () {
      let LineCharts = this.$refs.LineCharts;
      let myChart = echarts.init(LineCharts);
      let mockData = [{ name: '微信', value: 3328 }, { name: '南方+', value: 1045 }, { name: '东莞时间网', value: 834 }, { name: '东莞', value: 804 }, { name: '新浪微博', value: 532 }, { name: '今日头条', value: 493 }, { name: '腾讯新闻', value: 479 }, { name: '东莞阳光网', value: 387 }, { name: '东莞日报', value: 289 }, { name: '一点资讯', value: 287 }, { name: '东方头条网', value: 233 }, { name: '南方都市报', value: 228 }, { name: '新粤网', value: 207 }, { name: '南方plus', value: 206 }, { name: '网易新闻', value: 201 }, { name: '东方头条', value: 180 }, { name: '趣头条', value: 178 }, { name: '羊城派', value: 151 }, { name: '东莞时报', value: 143 }, { name: '莞讯网', value: 139 }, { name: '广州日报', value: 137 }, { name: '东莞阳光台', value: 132 }, { name: '搜狐新闻', value: 129 }, { name: '今日头条.APP', value: 116 }, { name: '东莞阳光平台', value: 108 }, { name: '腾讯新闻.APP', value: 107 }, { name: '南方网', value: 103 }, { name: 'UC头条', value: 98 }, { name: '凤凰新闻', value: 93 }, { name: '报告诉', value: 77 }, { name: '网易新闻.APP', value: 74 }, { name: '中国小康网', value: 64 }, { name: '东莞万江', value: 63 }, { name: '信息时报', value: 59 }, { name: '中国文明网', value: 58 }, { name: '东莞网', value: 57 }, { name: '搜狐新闻(自媒体)', value: 54 }, { name: '南方日报', value: 54 }, { name: '搜狐焦点', value: 53 }, { name: '阳光社区', value: 52 }, { name: '南方plus.APP', value: 47 }, { name: '阳光望牛墩', value: 46 }, { name: '中国报道', value: 43 }, { name: '新浪新闻', value: 43 }, { name: '房掌柜', value: 39 }, { name: '广州日报网', value: 38 }, { name: 'ZAKER', value: 38 }, { name: '一点资讯.APP', value: 35 }, { name: '聚焦东莞', value: 35 }, { name: '广州新闻网', value: 35 }, { name: '新浪', value: 31 }, { name: '东莞服务热线12345', value: 31 }, { name: '人民网', value: 29 }, { name: '阳光热线问政平台', value: 26 }, { name: '党报头条', value: 26 }, { name: '羊城晚报地方版', value: 24 }, { name: '网易房产', value: 23 }, { name: '中国网', value: 22 }, { name: '金羊网', value: 21 }, { name: '东莞长安', value: 21 }, { name: '百家号', value: 21 }, { name: '澎湃新闻', value: 20 }, { name: '读特', value: 19 }, { name: '东方头条.APP', value: 17 }, { name: '阳光石排', value: 16 }, { name: '新浪乐居', value: 16 }, { name: '微信邦', value: 16 }, { name: '搜狐新闻.APP', value: 16 }, { name: '人民日报', value: 16 }, { name: '百度新闻', value: 16 }, { name: '南方都市报.APP', value: 15 }, { name: '荔枝网', value: 15 }, { name: '华人头条', value: 15 }, { name: '广东建设报', value: 15 }, { name: '中国', value: 14 }, { name: '阳光黄江', value: 14 }, { name: '东方网', value: 14 }, { name: '网易', value: 12 }, { name: '搜狐网', value: 12 }, { name: '和讯', value: 12 }, { name: '文化莞城', value: 11 }, { name: '聊聊网', value: 11 }, { name: '58同镇', value: 11 }, { name: '凤凰网', value: 10 }, { name: '新浪网', value: 9 }, { name: '趣头条.APP', value: 9 }, { name: '凤岗网', value: 9 }, { name: '新快网_新快报', value: 8 }, { name: '上游新闻', value: 8 }, { name: '东莞市城市综合管理局', value: 8 }, { name: '大众网', value: 8 }, { name: '中国新闻网', value: 7 }, { name: '第一推', value: 7 }, { name: '大洋网', value: 7 }, { name: '新浪网', value: 6 }, { name: '新浪看点', value: 6 }, { name: '手机和讯网', value: 6 },].slice()
    
      // 随机颜色
      let randcolor = () => {
        let r = 100 + ~~(Math.random() * 100);
        let g = 135 + ~~(Math.random() * 100);
        let b = 100 + ~~(Math.random() * 100);
        return `rgb(${r}, ${g}, ${b})`
      }
      myChart.setOption({
        tooltip: {
          trigger: 'item',
          formatter: params => {
            const { name, value } = params
            return `
    平台:${name} 
    数量:
    ${value} `
    } }, series: [{ type: 'wordCloud', gridSize: 20, sizeRange: [12, 50], rotationRange: [0, 0], shape: 'circle', textStyle: { color: params => { return randcolor() }, emphasis: { shadowBlur: 10, shadowColor: '#333' } }, data: mockData }] }) },
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45

    自定义形状

    形状可以从 iconfont 找,下下来的图片可以通过在线工具转成 base64 格式然后在代码里引用

    let maskImage = new Image();
    maskImage.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMkAAADICAYAAABCmsWgAAAAAXNSR0IArs4c6QAAE3tJREFUeF7tXQnUdlMVflCGqNASkXmeRcak35+pTPWHiMg8ZB5SyZBYpYgyF6EylAj5DZF5qkRKZZkiIamQzKH16Fzr9XqHc+490z332W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+W0lQoAiJJoQOrbvlDQCTxh6U0FYqASFLowKpb/hAQSfxhKU2FIiCSFDqw6pY/BEQSf1hKU6EIiCSFDqy65Q8BkcQfltJUKAIiSaEDq275Q0Ak8YelNBWKwP8A8AR3+Szevr8AAAAASUVORK5CYII="
    
    myChart.setOption({
      series: [{
        type: 'wordCloud',
        // gridSize: 20,
        sizeRange: [12, 50],
        // rotationRange: [0, 0],
        rotationRange: [-45, 0, 45, 90],
        maskImage: maskImage, // 关键代码
        // ... 其他业务代码
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    动效

  • 相关阅读:
    Selenium二次封装与网络测试工具开发
    前后端接口设计与配置中心系统<二十九>-------HiAbility SDK开发1【 基础推送能力集成、OEM厂商推送能力集成】
    Android 12 适配攻略
    idea请问这两处标红是哪错了
    Debug Python project managed by poetry under VSCode in attach mode
    深度学习入门-与学习相关的技巧
    2022年全国最新消防设施操作员(中级消防设施操作员)真题题库及答案
    SAP-S4 BP 业务伙伴(客户与供应商)管理后台配置
    使用X2Keyarch迁移CentOS至浪潮信息KeyarchOS体验
    1662、检查两个字符串数组是否相等
  • 原文地址:https://blog.csdn.net/qq_37177115/article/details/126207173