vue 词云 echarts-wordcloud

<template>
  <div class="cloud-wrap">
    <div class="cloud-box" ref="cloudEl" />
  </div>
</template>

<script>
import echarts from "echarts";
import wordcloud from "echarts-wordcloud";
export default {
  props: {},
  data() {
    return {
      wordcloud: wordcloud,
      cloudData: [
        { value: 100, name: "文字" },
        { value: 400, name: "图片" },
        { value: 333, name: "参考" },
        { value: 855, name: "音视频" },
        { value: 343, name: "新媒体" },
        { value: 343, name: "测试1" },
        { value: 43, name: "测试2" },
        { value: 543, name: "测试3" },
        { value: 333, name: "测试4" },
        { value: 323, name: "测试5" },
        { value: 33, name: "测试6" },
        { value: 13, name: "测试7" },
        { value: 543, name: "测试8" },
        { value: 66, name: "测试9" },
        { value: 666, name: "测试10" },
      ],
    };
  },
  mounted() {
    this.drawCloud(this.$refs.cloudEl, this.cloudData);
  },
  methods: {
    drawCloud(wrapEl, data) {
      let myChart = echarts.init(wrapEl);
      var option = {
        tooltip: {
          show: true,
        },
        series: [
          {
            name: "热词",
            type: "wordCloud",
            sizeRange: [10, 30],
            rotationRange: [-20, 20],
            shape: "circle",
            left: "center",
            top: "center",
            width: "100%",
            height: "80%",
            gridSize: 3,
            textPadding: 0,
            autoSize: {
              enable: true,
              minSize: 6,
            },
            textStyle: {
              normal: {
                color: function () {
                  return (
                    "rgb(" +
                    [
                      Math.round(Math.random() * 250),
                      Math.round(Math.random() * 250),
                      Math.round(Math.random() * 250),
                    ].join(",") +
                    ")"
                  );
                },
              },
              emphasis: {
                shadowBlur: 10,
                shadowColor: "#333",
              },
            },
            data: data,
          },
        ],
      };
      myChart.setOption(option);
    },
  },
};
</script>
<style lang="scss" scoped>
.cloud-wrap {
  width: 490px;
  height: 366px;
  text-align: left;
  .cloud-box {
    width: 100%;
    height: 100%;
  }
}
</style>

延时向子组件传值

<wordCloudChart v-if="datas.bdrscy.length" :datas="datas.bdrscy"></wordCloudChart>

配置项

1 pie: {2 center : ['50%', '50%'], //默认全局居中

3 radius : [0, '75%'],4 clockWise : false, //默认逆时针

5 startAngle: 90,6 minAngle: 0, //最小角度改为0

7 selectedOffset: 10, //选中是扇区偏移量

8 itemStyle: {9 normal: {10 //color: 各异,

11 borderColor: '#fff',12 borderWidth: 1,13 label: {14 show: true,15 position: 'outer'

16 //textStyle: null // 默认使用全局文本样式,详见TEXTSTYLE

17 },18 labelLine: {19 show: true,20 length: 20,21 lineStyle: {22 //color: 各异,

23 width: 1,24 type: 'solid'

25 }26 }27 },28 emphasis: {29 //color: 各异,

30 borderColor: 'rgba(0,0,0,0)',31 borderWidth: 1,32 label: {33 show: false

34 //position: 'outer'

35 //textStyle: null // 默认使用全局文本样式,详见TEXTSTYLE

36 },37 labelLine: {38 show: false,39 length: 20,40 lineStyle: {41 //color: 各异,

42 width: 1,43 type: 'solid'

44 }45 }46 }47 }48 },49

50 map: {51 mapType: 'china', //各省的mapType暂时都用中文

52 mapLocation: {53 x : 'center',54 y : 'center'

55 //width // 自适应

56 //height // 自适应

57 },58 showLegendSymbol : true, //显示图例颜色标识(系列标识的小圆点),存在legend时生效

59 itemStyle: {60 normal: {61 //color: 各异,

62 borderColor: '#fff',63 borderWidth: 1,64 areaStyle: {65 color: '#ccc'//rgba(135,206,250,0.8)

66 },67 label: {68 show: false,69 textStyle: {70 color: 'rgba(139,69,19,1)'

71 }72 }73 },74 emphasis: { //也是选中样式

75 //color: 各异,

76 borderColor: 'rgba(0,0,0,0)',77 borderWidth: 1,78 areaStyle: {79 color: 'rgba(255,215,0,0.8)'

80 },81 label: {82 show: false,83 textStyle: {84 color: 'rgba(139,69,19,1)'

85 }86 }87 }88 }89 },90

91 force : {92 //数据map到圆的半径的最小值和最大值

93 minRadius : 10,94 maxRadius : 20,95 density : 1.0,96 attractiveness : 1.0,97 //初始化的随机大小位置

98 initSize : 300,99 //向心力因子,越大向心力越大

100 centripetal : 1,101 //冷却因子

102 coolDown : 0.99,103 //分类里如果有样式会覆盖节点默认样式

104 itemStyle: {105 normal: {106 //color: 各异,

107 label: {108 show: false

109 //textStyle: null // 默认使用全局文本样式,详见TEXTSTYLE

110 },111 nodeStyle : {112 brushType : 'both',113 color : '#f08c2e',114 strokeColor : '#5182ab'

115 },116 linkStyle : {117 strokeColor : '#5182ab'

118 }119 },120 emphasis: {121 //color: 各异,

122 label: {123 show: false

124 //textStyle: null // 默认使用全局文本样式,详见TEXTSTYLE

125 },126 nodeStyle : {},127 linkStyle : {}128 }129 }130 },131

132 chord : {133 radius : ['65%', '75%'],134 center : ['50%', '50%'],135 padding : 2,136 sort : 'none', //can be 'none', 'ascending', 'descending'

137 sortSub : 'none', //can be 'none', 'ascending', 'descending'

138 startAngle : 90,139 clockWise : false,140 showScale : false,141 showScaleText : false,142 itemStyle : {143 normal : {144 label : {145 show : true

146 //textStyle: null // 默认使用全局文本样式,详见TEXTSTYLE

147 },148 lineStyle : {149 width : 0,150 color : '#000'

151 },152 chordStyle : {153 lineStyle : {154 width : 1,155 color : '#666'

156 }157 }158 },159 emphasis : {160 lineStyle : {161 width : 0,162 color : '#000'

163 },164 chordStyle : {165 lineStyle : {166 width : 2,167 color : '#333'

168 }169 }170 }171 }172 },173

174 island: {175 r: 15,176 calculateStep: 0.1 //滚轮可计算步长 0.1 = 10%

177 },178

179 markPoint : {180 symbol: 'pin', //标注类型

181 symbolSize: 10, //标注大小,半宽(半径)参数,当图形为方向或菱形则总宽度为symbolSize * 2

182 //symbolRotate : null, // 标注旋转控制

183 itemStyle: {184 normal: {185 //color: 各异,

186 //borderColor: 各异, // 标注边线颜色,优先于color

187 borderWidth: 2, //标注边线线宽,单位px,默认为1

188 label: {189 show: true,190 position: 'inside' //可选为'left'|'right'|'top'|'bottom'

191 //textStyle: null // 默认使用全局文本样式,详见TEXTSTYLE

192 }193 },194 emphasis: {195 //color: 各异

196 label: {197 show: true

198 //position: 'inside' // 'left'|'right'|'top'|'bottom'

199 //textStyle: null // 默认使用全局文本样式,详见TEXTSTYLE

200 }201 }202 }203 },204

205 markLine : {206 //标线起始和结束的symbol介绍类型,如果都一样,可以直接传string

207 symbol: ['circle', 'arrow'],208 //标线起始和结束的symbol大小,半宽(半径)参数,当图形为方向或菱形则总宽度为symbolSize * 2

209 symbolSize: [2, 4],210 //标线起始和结束的symbol旋转控制

211 //symbolRotate : null,

212 itemStyle: {213 normal: {214 //color: 各异, // 标线主色,线色,symbol主色

215 //borderColor: 随color, // 标线symbol边框颜色,优先于color

216 borderWidth: 2, //标线symbol边框线宽,单位px,默认为2

217 label: {218 show: false,219 //可选为 'start'|'end'|'left'|'right'|'top'|'bottom'

220 position: 'inside',221 textStyle: { //默认使用全局文本样式,详见TEXTSTYLE

222 color: '#333'

223 }224 },225 lineStyle: {226 //color: 随borderColor, // 主色,线色,优先级高于borderColor和color

227 //width: 随borderWidth, // 优先于borderWidth

228 type: 'solid',229 shadowColor : 'rgba(0,0,0,0)', //默认透明

230 shadowBlur: 5,231 shadowOffsetX: 3,232 shadowOffsetY: 3

233 }234 },235 emphasis: {236 //color: 各异

237 label: {238 show: false

239 //position: 'inside' // 'left'|'right'|'top'|'bottom'

240 //textStyle: null // 默认使用全局文本样式,详见TEXTSTYLE

241 },242 lineStyle : {}243 }244 }245 },246

247 textStyle: {248 decoration: 'none',249 fontFamily: 'Arial, Verdana, sans-serif',250 fontFamily2: '微软雅黑', //IE8- 字体模糊并且不支持不同字体混排,额外指定一份

251 fontSize: 12,252 fontStyle: 'normal',253 fontWeight: 'normal'

254 },
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 199,902评论 5 468
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 84,037评论 2 377
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 146,978评论 0 332
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,867评论 1 272
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,763评论 5 360
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,104评论 1 277
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,565评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,236评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,379评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,313评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,363评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,034评论 3 315
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,637评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,719评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,952评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,371评论 2 346
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 41,948评论 2 341

推荐阅读更多精彩内容