首页 > 其他分享 >⑧ vue+echarts实现热词分析

⑧ vue+echarts实现热词分析

时间:2022-11-22 11:55:55浏览次数:44  
标签:count vue 1.0 name 热词 rank heat echarts

依赖

"dependencies": {
  "echarts": "^4.0.4",
  "echarts-wordcloud": "^1.1.3",
},

tip: echarts-wordcloud 现在有 2.0 和 1.x 两个版本,2.0 对应 echarts 5.x 版本

实现

html

<template>
  <div>
    <div class="chart" ref="chartWordCloud"></div>
  </div>
</template>
<style scoped>
.chart {
  width: 100%;
  height: 600px;
}
</style>

js

<script>
import { ref } from 'vue'
import echarts from 'echarts'
require('echarts-wordcloud')
import hotWordsData from '../data/hotWords'
const chartEffect = () => {
  // 处理数据
  const originData = hotWordsData.data.map(item => ({
    name: item.name,
    value: item.heat
  }))
  // 随机生成颜色
  const randomColor = () => {
    return 'rgb(' + [
      Math.round(Math.random() * 255),
      Math.round(Math.random() * 255),
      Math.round(Math.random() * 255)
    ].join(',') + ')'
  }
  return { originData, randomColor }
}
export default {
  name: 'hotWords',
  mounted() {
    const chart = echarts.init(this.$refs.chartWordCloud)
    chart.setOption({
      series: [{
        type: 'wordCloud',
        left: 'center',
        top: 'center',
        right: null,
        bottom: null,
        width: '100%',
        height: '100%',
        sizeRange: [10, 80],
        rotationRange: [-90, 90],
        rotationStep: 45,
        gridSize: 8,
        drawOutOfBound: false,
        textStyle: {
          normal: {
            fontFamily: 'sans-serif',
            fontWeight: 'normal'
          },
          emphasis: {
            shadowBlur: 10,
            shadowColor: '#333'
          }
        },
        data: this.data
      }]
    })
  },
  setup() {
    const { originData, randomColor } = chartEffect()
    const data = ref(originData.map(val => ({
      ...val,
      textStyle: {
        normal: {
          color: randomColor()
        }
      }
    })))
    return { data }
  },
  
}
</script>

数据

{
  "detail": "微博热搜关键词",
  "data": [
    { "name": "世界杯", "rank": 1.0, "heat": 185, "count": 1 },
    { "name": "直播间", "rank": 1.0, "heat": 100, "count": 1 },
    { "name": "377面霜", "rank": 1.0, "heat": 66, "count": 1 },
    { "name": "李佳琪", "rank": 1.0, "heat": 55, "count": 1 },
    { "name": "捡漏", "rank": 1.0, "heat": 55, "count": 1 },
    { "name": "377精华", "rank": 1.0, "heat": 66, "count": 1 },
    { "name": "广州疫情", "rank": 1.0, "heat": 165, "count": 1 },
    { "name": "海珠疫情", "rank": 1.0, "heat": 155, "count": 1 },
    { "name": "疫情", "rank": 1.0, "heat": 225, "count": 1 },
    { "name": "城中村", "rank": 1.0, "heat": 85, "count": 1 },
    { "name": "石家庄", "rank": 1.0, "heat": 105, "count": 1 },
    { "name": "摆烂政策", "rank": 1.0, "heat": 105, "count": 1 },
    { "name": "大学生", "rank": 1.0, "heat": 95, "count": 1 },
    { "name": "阿根廷vs沙特阿拉伯", "rank": 1.0, "heat": 55, "count": 1 },
    { "name": "梅西世界杯首秀", "rank": 1.0, "heat": 55, "count": 1 },
    { "name": "广州新增本土感染者8210例", "rank": 1.0, "heat": 85, "count": 1 },
    { "name": "成都疫情防控", "rank": 1.0, "heat": 65, "count": 1 },
    { "name": "今晚看梅西阿根廷", "rank": 1.0, "heat": 55, "count": 1 },
    { "name": "美国vs威尔士", "rank": 1.0, "heat": 55, "count": 1 },
    { "name": "中国男足", "rank": 1.0, "heat": 55, "count": 1 }
  ]
}

效果

标签:count,vue,1.0,name,热词,rank,heat,echarts
From: https://www.cnblogs.com/pleaseAnswer/p/16914691.html

相关文章

  • vue 项目中,后端返回文件流,导出excel
    之前写过文件流导出excel,这次直接把上次的代码拿过来复制粘贴,但是导出的表格里面没有数据,只显示undefined。这是之前的代码//api接口页面//excel导出接口export......
  • VUE
    VUESoc:HTML+css+js:视图网络通信:axios页面跳转:vue-router状态管理:vuexVue-UI:ICE  M:模型V:视图C:控制器View:JSP{{}}DATA:mvvm:数据双向绑定 虚拟Dom:利......
  • swiper鼠标悬停(自由切换),拒绝大佬,珍爱生命![email protected]
    [email protected]@4.1.1--save-dev实测有效!JavaScript:<script>import{Swiper,SwiperSlide}from'vue-awesome......
  • vue2 计算属性9 watch immediate
    watch:监听数据发生的变化 newVal是变化后的新值,oldVal是变化前的旧值 一般都是带着接口查询的watch:{username(newVal){if(newVal==='')return$get('https:......
  • vue2-vm.$set,vm.$delete实现(三)
    vm.$set实现语法:vm.$set(target,key,value)参数:{Object|Array}target{String|Number}key{any}value返回值:{Function}unwatch用法:在object上设置一个属......
  • vue学习笔记
     --vue笔记 --页面带参数跳转testBang(){this.$router.push({path:"/layout/channel/channelAuth",query:{startDate:"test",}})}--获取url入参lettok......
  • avue框架 拼接后端返回的数据到table中
    根据要求展示下列详细地址情况: 后端返回的数据:  具体实现步骤:  {label:"详细地址",prop:"buildingName",display:false,width:130,......
  • vue3 封装axios
    1添加一个新的http.js文件封装axios 引入axios //引入Axiosimportaxiosfrom'axios'定义一个根地址//视你自己的接口地址而定varroot2='http://121.4.6......
  • Vue3笔记 - minxin和hook的使用与对比
    minxin和hook的使用与对比目录minxin和hook的使用与对比1.mixin(Vue2)2.hook(Vue3)3.mixin和hook的对比1.mixin(Vue2)mixin可以把多个组件共用的配置提取成一......
  • vue3 路由的使用
    添加一个router.js配置文件import{createRouter,createWebHistory}from'vue-router'createRouter:用来创建路由createWebHistory:url的格式不带#。导入你......