[本文出自天外归云的博客园]

简介

在Vue中使用E-Charts可以用V-Charts,词云图在V-Charts官网中介绍比较简单,如果想更多定制的话,官网上说要在extend属性中进行扩展。

V-Charts官网关于V-Charts中词云图相关的介绍

Echart官网Echarts github中关于词云图相关的介绍

V-Charts官网关于extend配置项的介绍

使用示例

以下是扩展后的样子:

<template>
<div>
<el-row>
<h3 class="float-left"><i class="el-icon-check"></i> 分词统计</h3>
</el-row>
<el-row :gutter="20">
<el-col :span="3">
<SelectOption :selected.sync="versionSelected"
:options="versionOptions"
placeholder="请选择版本"></SelectOption>
</el-col>
<el-col :span="3">
<SelectOption :selected.sync="platformSelected"
:options="platformOptions"
placeholder="请选择平台"></SelectOption>
</el-col>
<el-col :span="6">
<DateTimePicker :dateValue.sync="dateValue"></DateTimePicker>
</el-col>
</el-row>
<!-- <div id="wordCloud">
<wordcloud :rotate="{from: -5, to: 5, numOfOrientation: 5 }"
fontScale="n"
spiral="rectangular"
:data="cloudWords"
nameKey="word"
valueKey="cou"
:wordClick="showTimes">
</wordcloud>
</div> -->
<ve-wordcloud v-if="showChart"
width="100%"
height="700px"
:data="chartData"
:extend="chartExtend"
:settings="chartSettings"></ve-wordcloud>
<div style="text-align:left;margin-left:10px"
v-else>没数据</div>
</div>
</template>
<style>
</style>
<script>
import { SelectOption, DateTimePicker } from '@/components/common'
import { getFeedbackWordCloud } from '@/api/feedbacks'
import { EventBus } from '@/bus.js'
// import wordcloud from 'vue-wordcloud'
export default {
name: 'wordCloud',
components: {
// wordcloud,
SelectOption,
DateTimePicker
},
data () {
return {
showChart: true,
chartSettings: {
color: ['#4876FF', '#87CEFA', '#98F5FF', '#BBFFFF']
},
chartExtend: {
series: {
rotationRange: [0, 0],
sizeRange: [50, 150],
width: '100%',
height: '100%',
drawOutOfBound: true,
textStyle: {
normal: {
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'
}
}
}
},
chartData: {
columns: ['word', 'cou'],
rows: []
},
version: [],
versionSelected: 'all',
versionOptions: [],
platform: [],
platformSelected: 'all',
platformOptions: [],
myProjectId: this.$route.query.feedbackProject,
dateValue: [new Date(2018, 9, 1, 0, 0), new Date(2018, 9, 8, 0, 0)]
}
},
methods: {
/**
* 阅读vue-wordcloud
* WordCloud.vue源代码即可知此函数是必须的
*/
showTimes (val1, val2) {
for (var i in val2.data) {
if (val2.data[i]['text'] === val1) {
var tip = '"' + val1 + '" 分词统计次数:' + val2.data[i]['cou']
this.$alert(tip, '', {})
}
}
},
getFbWordCloud () {
let _this = this
let projectId = _this.myProjectId
let startTime = _this.startTime
let endTime = _this.endTime
let clientVersion = _this.versionSelected
let origin = _this.platformSelected
if (origin === 'all') {
origin = -1
}
getFeedbackWordCloud(projectId, startTime, endTime, clientVersion, origin).then(data => {
_this.showChart = true
_this.chartData.rows = data
if (data === undefined || data.length === 0) {
_this.showChart = false
}
})
},
initVersion () {
let _this = this
// Version Select Options
_this.versionOptions = []
for (let index = 0; index < _this.version.length; index++) {
_this.versionOptions.push({
'id': (_this.version)[index].name,
'label': (_this.version)[index].name,
'value': (_this.version)[index].name
})
}
_this.versionSelected = 'all'
},
initPlatform () {
let _this = this
// Platform Select Options
_this.platformOptions = []
for (let index = 0; index < _this.platform.length; index++) {
_this.platformOptions.push({
'id': (_this.platform)[index].id,
'label': (_this.platform)[index].name,
'value': (_this.platform)[index].id
})
}
_this.platformSelected = 'all'
},
setDateValue () {
let _this = this
let sDate = _this.dateValue[0]
let eDate = _this.dateValue[1]
_this.startTime = sDate.getFullYear() + '-' + (sDate.getMonth() + 1) + '-' + sDate.getDate() + ' 00:00:00'
_this.endTime = eDate.getFullYear() + '-' + (eDate.getMonth() + 1) + '-' + eDate.getDate() + ' 00:00:00'
// console.log(_this.startTime)
// console.log(_this.endTime)
}
},
created () {
let _this = this
_this.setDateValue()
// Get projectId
EventBus.$on('projectId', projectId => {
// console.log('[WordCloud下车]projectId')
_this.myProjectId = projectId
})
// Get version
EventBus.$on('version', version => {
// console.log('[WordCloud下车]version')
_this.version = version
_this.initVersion()
})
// Get origin
EventBus.$on('origin', origin => {
// console.log('[WordCloud下车]origin')
_this.platform = origin
_this.initPlatform()
})
},
mounted () {
this.getFbWordCloud()
},
watch: {
versionSelected: {
immediate: false,
handler: function () {
this.getFbWordCloud()
}
},
platformSelected: {
immediate: false,
handler: function () {
this.getFbWordCloud()
}
},
dateValue: {
immediate: false,
handler: function () {
this.setDateValue()
this.getFbWordCloud()
}
},
version: {
immediate: false,
handler: function () {
this.getFbWordCloud()
}
},
platform: {
immediate: false,
handler: function () {
this.getFbWordCloud()
}
}
}
}
</script>

上面是我使用词云图所在的整个单文件组件,其中词云图使用相关只需要关注以下三点:

1.变量chartExtend在ve-wordcloud标签中对应的插槽位

2.我是全局引入的ve-wordcloud,所以如果你没有全局引入,一定要在组件中import下:

// import wordcloud from 'vue-wordcloud'

3.变量chartSettings是官网上给出的标准设置插槽位对应的变量值

V-Charts中使用extend属性定制词云图的更多相关文章

  1. 使用Python定制词云

    一.实验介绍 1.1 实验内容 在互联网时代,人们获取信息的途径多种多样,大量的信息涌入到人们的视线中.如何从浩如烟海的信息中提炼出关键信息,滤除垃圾信息,一直是现代人关注的问题.在这个信息爆炸的时代 ...

  2. (数据科学学习手札71)在Python中制作个性化词云图

    本文对应脚本及数据已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 一.简介 词云图是文本挖掘中用来表征词频的数据可视化 ...

  3. 用Python制作酷炫词云图,原来这么简单!

    一.简介词云图是文本挖掘中用来表征词频的数据可视化图像,通过它可以很直观地展现文本数据中地高频词:! 图1 词云图示例 在Python中有很多可视化框架可以用来制作词云图,如pyecharts,但这些 ...

  4. jQuery中,$.extend,$obj.extend和$.fn.extend三者的区别

    jQuery中,$.extend,$obj.extend和$.fn.extend三者的区别 现在做的一个项目,所使用的框架是基于jQuery扩展的,于是平时学了一下jQuery,了解到了它的扩展函数: ...

  5. js中的extend,可实现浅拷贝深拷贝

    js中的extend   1.    JS中substring与substr的区别 之前在项目中用到substring方法,因为C#中也有字符串的截取方法Substring方法,当时也没有多想就误以为 ...

  6. js中的extend

    js中的extend   1.    JS中substring与substr的区别 之前在项目中用到substring方法,因为C#中也有字符串的截取方法Substring方法,当时也没有多想就误以为 ...

  7. jQuery中样式和属性模块简单分析

    1.行内样式操作 目标:扩展框架实现行内样式的增删改查 1.1 创建 css 方法 目标:实现单个样式或者多个样式的操作 1.1.1 css方法 -获取样式 注意:使用 style 属性只能获取行内样 ...

  8. (转)jQuery中的extend()方法

    本文转自:http://www.xiabingbao.com/jquery/2015/05/30/jquery-extend 原文的排版要比这里美观很多,建议去原文查看.本文仅仅作为个人的mark,方 ...

  9. HTML 5 中的标准属性

    HTML 全局属性 HTML 属性赋予元素意义和语境. 下面的全局属性可用于任何 HTML 元素. (5)= HTML5 中添加的属性. 属性 描述 accesskey 规定激活元素的快捷键. cla ...

随机推荐

  1. BZOJ.3631.[JLOI2014]松鼠的新家(树上差分)

    题目链接 树剖/差分裸题.. //28260kb 584ms #include <cstdio> #include <cctype> #include <algorith ...

  2. 如何查看linux版本信息

    查看系统信息 [root@root]# hostnamectl Static hostname: root Icon name: computer-desktop Chassis: desktop M ...

  3. Cocos Creator 节点

    //节点从创建到节点挂载一些过程 1.JS中节点使用: a.创建:在properties中定义节点(可能包括节点的默认值和类型): b.挂载:在相应的方法中获取节点获取相应节点,挂载到父元素 例== ...

  4. dedecms在后台替换文章标题、内容、摘要、关键字

    dedecms在后台替换文章标题.内容.摘要.关键字所在的字段为: 后台替换文章内容 数据表:dede_addonarticle 字段:body 后台替换文章摘要内容 数据表:dede_archive ...

  5. 微信小程序-转发

    仅供参考 1,js: onShareAppMessage(res) { return { title: '我在使用俺搜·找客户,10万+材料人都在用,就差你了', path: '/pages/inde ...

  6. pygame-KidsCanCode系列jumpy-part2-加速度与摩擦力

    上一节,我们整理了一个游戏开发的新框架(即:Game类),本节将运用这个框架,实现基本的加速度及摩托力效果. 先定义游戏的精灵(下面代码命名为sprites.py) from part_02.sett ...

  7. 当前线程不在单线程单元中,因此无法实例化 ActiveX 控件“8856f961-340a-11d0-a96“

    在做采集时,有些网页因服务器限制用webclient或者webrequest不能获取html,这时我们可以用webbrowser的方法来绕过对方服务器的限制,但是在实例化webbrowser 的时候发 ...

  8. C#实战技能之WebApi+Task+WebSocket

    一.背景介绍 环境的局限性: 用户在使用XX客户端的时候,必须每台电脑都安装打印组件,同时由于XX客户端使用的是 websocket进行通讯,这就必须限制用户的电脑浏览器必须是IE10.0+以上版本, ...

  9. 本机ip、127.0.0.1和0.0.0.0区别及内环流量

    本机ip.127.0.0.1和0.0.0.0区别及内环流量 所谓内环流量 简单的说是指 计算机内部,程序间通讯产生的流量,或者叫 本地流量,对应的是来自网络的流量. 比如,你安装了卡巴斯基,avast ...

  10. java调用sap的webservice(需要登录验证)

    1.Base64.java /* * Copyright (C) 2010 The Android Open Source Project * * Licensed under the Apache ...