Echart 词云图 上手代码 同含(echarts-wordcloud.js)最简单的教程 复制可用

先上示例图:

这是自定义图片的示例图

先给最简单的非自定义图代码 

  1 <html>
  2     <head>
  3         <meta charset="utf-8">
  4         <!-- <script src=‘https://cdn.bootcss.com/echarts/3.7.0/echarts.simple.js‘></script> -->
  5
  6         <script src=‘../../echarts/echarts.min.js‘></script>
  7
  8         <script src=‘../dist/echarts-wordcloud.js‘></script>
  9     </head>
 10     <body>
 11         <style>
 12             html, body, #main {
 13                 width: 100%;
 14                 height: 100%;
 15                 margin: 0;
 16             }
 17         </style>
 18         <div id=‘main‘></div>
 19         <script>
 20             var chart = echarts.init(document.getElementById(‘main‘));
 21
 22             var option = {
 23                 tooltip: {},
 24                 series: [ {
 25                     type: ‘wordCloud‘,
 26                     gridSize: 2,
 27                     sizeRange: [12, 50],
 28                     rotationRange: [-90, 90],
 29                     shape: ‘pentagon‘,
 30                     width: 600,
 31                     height: 400,
 32                     drawOutOfBound: true,
 33                     textStyle: {
 34                         normal: {
 35                             color: function () {
 36                                 return ‘rgb(‘ + [
 37                                     Math.round(Math.random() * 160),
 38                                     Math.round(Math.random() * 160),
 39                                     Math.round(Math.random() * 160)
 40                                 ].join(‘,‘) + ‘)‘;
 41                             }
 42                         },
 43                         emphasis: {
 44                             shadowBlur: 10,
 45                             shadowColor: ‘#333‘
 46                         }
 47                     },
 48                     data: [
 49                         {
 50                             name: ‘Sam S Club‘,
 51                             value: 10000,
 52                             textStyle: {
 53                                 normal: {
 54                                     color: ‘black‘
 55                                 },
 56                                 emphasis: {
 57                                     color: ‘red‘
 58                                 }
 59                             }
 60                         },
 61                         {
 62                             name: ‘Macys‘,
 63                             value: 6181
 64                         },
 65                         {
 66                             name: ‘Amy Schumer‘,
 67                             value: 4386
 68                         },
 69                         {
 70                             name: ‘Jurassic World‘,
 71                             value: 4055
 72                         },
 73                         {
 74                             name: ‘Charter Communications‘,
 75                             value: 2467
 76                         },
 77                         {
 78                             name: ‘Chick Fil A‘,
 79                             value: 2244
 80                         },
 81                         {
 82                             name: ‘Planet Fitness‘,
 83                             value: 1898
 84                         },
 85                         {
 86                             name: ‘Pitch Perfect‘,
 87                             value: 1484
 88                         },
 89                         {
 90                             name: ‘Express‘,
 91                             value: 1112
 92                         },
 93                         {
 94                             name: ‘Home‘,
 95                             value: 965
 96                         },
 97                         {
 98                             name: ‘Johnny Depp‘,
 99                             value: 847
100                         },
101                         {
102                             name: ‘Lena Dunham‘,
103                             value: 582
104                         },
105                         {
106                             name: ‘Lewis Hamilton‘,
107                             value: 555
108                         },
109                         {
110                             name: ‘KXAN‘,
111                             value: 550
112                         },
113                         {
114                             name: ‘Mary Ellen Mark‘,
115                             value: 462
116                         },
117                         {
118                             name: ‘Farrah Abraham‘,
119                             value: 366
120                         },
121                         {
122                             name: ‘Rita Ora‘,
123                             value: 360
124                         },
125                         {
126                             name: ‘Serena Williams‘,
127                             value: 282
128                         },
129                         {
130                             name: ‘NCAA baseball tournament‘,
131                             value: 273
132                         },
133                         {
134                             name: ‘Point Break‘,
135                             value: 265
136                         }
137                     ]
138                 } ]
139             };
140
141             chart.setOption(option);
142
143             window.onresize = chart.resize;
144         </script>
145     </body>
146 </html>

官方非自定义图片

下面这个是自定义图片教程

1,数据填写

1 var keywords = {
2               "visualMap": 22199,
3               "continuous": 10288,
4               "contoller": 620,
5               "series": 274470,
6               "gauge": 12311
7                 .......
8         }

这一部分都是那些文字,可以用ajax或者内嵌java代码填写

2,下载图片(尽量下载那些背景纯白的图片)

    

3,更改路径(不需要考虑动漫人物颜色)

1 maskImage.src = ‘../img/test.png‘;

4,复制源码:

  1 <html>
  2     <head>
  3         <meta charset="utf-8">
  4         <script src=‘https://cdn.bootcss.com/echarts/3.7.2/echarts.simple.js‘></script>
  5         <script src=‘../dist/echarts-wordcloud.js‘></script>
  6     </head>
  7     <body>
  8         <style>
  9             html, body, #main {
 10                 width: 100%;
 11                 height: 100%;
 12                 margin: 0;
 13             }
 14         </style>
 15         <div id=‘main‘></div>
 16         <script>
 17             var chart = echarts.init(document.getElementById(‘main‘));
 18
 19             var keywords = {
 20               "visualMap": 22199,
 21               "continuous": 10288,
 22               "contoller": 620,
 23               "series": 274470,
 24               "gauge": 12311,
 25               "detail": 1206,
 26               "piecewise": 4885,
 27               "textStyle": 32294,
 28               "markPoint": 18574,
 29               "pie": 38929,
 30               "roseType": 969,
 31               "label": 37517,
 32               "emphasis": 12053,
 33               "yAxis": 57299,
 34               "name": 15418,
 35               "type": 22905,
 36               "gridIndex": 5146,
 37               "normal": 49487,
 38               "itemStyle": 33837,
 39               "min": 4500,
 40               "silent": 5744,
 41               "animation": 4840,
 42               "offsetCenter": 232,
 43               "inverse": 3706,
 44               "borderColor": 4812,
 45               "markLine": 16578,
 46               "line": 76970,
 47               "radiusAxis": 6704,
 48               "radar": 15964,
 49               "data": 60679,
 50               "dataZoom": 24347,
 51               "tooltip": 43420,
 52               "toolbox": 25222,
 53               "geo": 16904,
 54               "parallelAxis": 4029,
 55               "parallel": 5319,
 56               "max": 3393,
 57               "bar": 43066,
 58               "heatmap": 3110,
 59               "map": 20285,
 60               "animationDuration": 3425,
 61               "animationDelay": 2431,
 62               "splitNumber": 5175,
 63               "axisLine": 12738,
 64               "lineStyle": 19601,
 65               "splitLine": 7133,
 66               "axisTick": 8831,
 67               "axisLabel": 17516,
 68               "pointer": 590,
 69               "color": 23426,
 70               "title": 38497,
 71               "formatter": 15214,
 72               "slider": 7236,
 73               "legend": 66514,
 74               "grid": 28516,
 75               "smooth": 1295,
 76               "smoothMonotone": 696,
 77               "sampling": 757,
 78               "feature": 12815,
 79               "saveAsImage": 2616,
 80               "polar": 6279,
 81               "calculable": 879,
 82               "backgroundColor": 9419,
 83               "excludeComponents": 130,
 84               "show": 20620,
 85               "text": 2592,
 86               "icon": 2782,
 87               "dimension": 478,
 88               "inRange": 1060,
 89               "animationEasing": 2983,
 90               "animationDurationUpdate": 2259,
 91               "animationDelayUpdate": 2236,
 92               "animationEasingUpdate": 2213,
 93               "xAxis": 89459,
 94               "angleAxis": 5469,
 95               "showTitle": 484,
 96               "dataView": 2754,
 97               "restore": 932,
 98               "timeline": 10104,
 99               "range": 477,
100               "value": 5732,
101               "precision": 878,
102               "target": 1433,
103               "zlevel": 5361,
104               "symbol": 8718,
105               "interval": 7964,
106               "symbolSize": 5300,
107               "showSymbol": 1247,
108               "inside": 8913,
109               "xAxisIndex": 3843,
110               "orient": 4205,
111               "boundaryGap": 5073,
112               "nameGap": 4896,
113               "zoomLock": 571,
114               "hoverAnimation": 2307,
115               "legendHoverLink": 3553,
116               "stack": 2907,
117               "throttle": 466,
118               "connectNulls": 897,
119               "clipOverflow": 826,
120               "startValue": 551,
121               "minInterval": 3292,
122               "opacity": 3097,
123               "splitArea": 4775,
124               "filterMode": 635,
125               "end": 409,
126               "left": 6475,
127               "funnel": 2238,
128               "lines": 6403,
129               "baseline": 431,
130               "align": 2608,
131               "coord": 897,
132               "nameTextStyle": 7477,
133               "width": 4338,
134               "shadowBlur": 4493,
135               "effect": 929,
136               "period": 225,
137               "areaColor": 631,
138               "borderWidth": 3654,
139               "nameLocation": 4418,
140               "position": 11723,
141               "containLabel": 1701,
142               "scatter": 10718,
143               "areaStyle": 5310,
144               "scale": 3859,
145               "pieces": 414,
146               "categories": 1000,
147               "selectedMode": 3825,
148               "itemSymbol": 273,
149               "effectScatter": 7147,
150               "fontStyle": 3376,
151               "fontSize": 3386,
152               "margin": 1034,
153               "iconStyle": 2257,
154               "link": 1366,
155               "axisPointer": 5245,
156               "showDelay": 896,
157               "graph": 22194,
158               "subtext": 1442,
159               "selected": 2881,
160               "barCategoryGap": 827,
161               "barGap": 1094,
162               "barWidth": 1521,
163               "coordinateSystem": 3622,
164               "barBorderRadius": 284,
165               "z": 4014,
166               "polarIndex": 1456,
167               "shadowOffsetX": 3046,
168               "shadowColor": 3771,
169               "shadowOffsetY": 2475,
170               "height": 1988,
171               "barMinHeight": 575,
172               "lang": 131,
173               "symbolRotate": 2752,
174               "symbolOffset": 2549,
175               "showAllSymbol": 942,
176               "transitionDuration": 993,
177               "bottom": 3724,
178               "fillerColor": 229,
179               "nameMap": 1249,
180               "barMaxWidth": 747,
181               "radius": 2103,
182               "center": 2425,
183               "magicType": 3276,
184               "labelPrecision": 248,
185               "option": 654,
186               "seriesIndex": 935,
187               "controlPosition": 121,
188               "itemGap": 3188,
189               "padding": 3481,
190               "shadowStyle": 347,
191               "boxplot": 1394,
192               "labelFormatter": 264,
193               "realtime": 631,
194               "dataBackgroundColor": 239,
195               "showDetail": 247,
196               "showDataShadow": 217,
197               "x": 684,
198               "valueDim": 499,
199               "onZero": 931,
200               "right": 3255,
201               "clockwise": 1035,
202               "itemWidth": 1732,
203               "trigger": 3840,
204               "axis": 379,
205               "selectedOffset": 670,
206               "startAngle": 1293,
207               "minAngle": 590,
208               "top": 4637,
209               "avoidLabelOverlap": 870,
210               "labelLine": 3785,
211               "sankey": 2933,
212               "endAngle": 213,
213               "start": 779,
214               "roam": 1738,
215               "fontWeight": 2828,
216               "fontFamily": 2490,
217               "subtextStyle": 2066,
218               "indicator": 853,
219               "sublink": 708,
220               "zoom": 1038,
221               "subtarget": 659,
222               "length": 1060,
223               "itemSize": 505,
224               "controlStyle": 452,
225               "yAxisIndex": 2529,
226               "edgeLabel": 1188,
227               "radiusAxisIndex": 354,
228               "scaleLimit": 1313,
229               "geoIndex": 535,
230               "regions": 1892,
231               "itemHeight": 1290,
232               "nodes": 644,
233               "candlestick": 3166,
234               "crossStyle": 466,
235               "edges": 369,
236               "links": 3277,
237               "layout": 846,
238               "barBorderColor": 721,
239               "barBorderWidth": 498,
240               "treemap": 3865,
241               "y": 367,
242               "valueIndex": 704,
243               "showLegendSymbol": 482,
244               "mapValueCalculation": 492,
245               "optionToContent": 264,
246               "handleColor": 187,
247               "handleSize": 271,
248               "showContent": 1853,
249               "angleAxisIndex": 406,
250               "endValue": 327,
251               "triggerOn": 1720,
252               "contentToOption": 169,
253               "buttonColor": 71,
254               "rotate": 1144,
255               "hoverLink": 335,
256               "outOfRange": 491,
257               "textareaColor": 58,
258               "textareaBorderColor": 58,
259               "textColor": 60,
260               "buttonTextColor": 66,
261               "category": 336,
262               "hideDelay": 786,
263               "alwaysShowContent": 1267,
264               "extraCssText": 901,
265               "effectType": 277,
266               "force": 1820,
267               "rippleEffect": 723,
268               "edgeSymbolSize": 329,
269               "showEffectOn": 271,
270               "gravity": 199,
271               "edgeLength": 193,
272               "layoutAnimation": 152,
273               "length2": 169,
274               "enterable": 957,
275               "dim": 83,
276               "readOnly": 143,
277               "levels": 444,
278               "textGap": 256,
279               "pixelRatio": 84,
280               "nodeScaleRatio": 232,
281               "draggable": 249,
282               "brushType": 158,
283               "radarIndex": 152,
284               "large": 182,
285               "edgeSymbol": 675,
286               "largeThreshold": 132,
287               "leafDepth": 73,
288               "childrenVisibleMin": 73,
289               "minSize": 35,
290               "maxSize": 35,
291               "sort": 90,
292               "funnelAlign": 61,
293               "source": 336,
294               "nodeClick": 200,
295               "curveness": 350,
296               "areaSelectStyle": 104,
297               "parallelIndex": 52,
298               "initLayout": 359,
299               "trailLength": 116,
300               "boxWidth": 20,
301               "back": 53,
302               "rewind": 110,
303               "zoomToNodeRatio": 80,
304               "squareRatio": 60,
305               "parallelAxisDefault": 358,
306               "checkpointStyle": 440,
307               "nodeWidth": 49,
308               "color0": 62,
309               "layoutIterations": 56,
310               "nodeGap": 54,
311               "color(Array": 76,
312               "<string>)": 76,
313               "repulsion": 276,
314               "tiled": 105,
315               "currentIndex": 145,
316               "axisType": 227,
317               "loop": 97,
318               "playInterval": 112,
319               "borderColor0": 23,
320               "gap": 43,
321               "autoPlay": 123,
322               "showPlayBtn": 25,
323               "breadcrumb": 119,
324               "colorMappingBy": 85,
325               "id": 18,
326               "blurSize": 85,
327               "minOpacity": 50,
328               "maxOpacity": 54,
329               "prevIcon": 12,
330               "children": 21,
331               "shape": 98,
332               "nextIcon": 12,
333               "showNextBtn": 17,
334               "stopIcon": 21,
335               "visibleMin": 83,
336               "visualDimension": 97,
337               "colorSaturation": 56,
338               "colorAlpha": 66,
339               "emptyItemWidth": 10,
340               "inactiveOpacity": 4,
341               "activeOpacity": 4,
342               "showPrevBtn": 19,
343               "playIcon": 26,
344               "ellipsis": 19,
345               "gapWidth": 19,
346               "borderColorSaturation": 10,
347               "handleIcon": 2,
348               "handleStyle": 6,
349               "borderType": 1,
350               "constantSpeed": 1,
351               "polyline": 2,
352               "blendMode": 1,
353               "dataBackground": 1,
354               "textAlign": 1,
355               "textBaseline": 1,
356               "brush": 3
357             };
358
359             var data = [];
360             for (var name in keywords) {
361                 data.push({
362                     name: name,
363                     value: Math.sqrt(keywords[name])
364                 })
365             }
366
367             var maskImage = new Image();
368
369             var option = {
370                 series: [ {
371                     type: ‘wordCloud‘,
372                     sizeRange: [10, 100],
373                     rotationRange: [-90, 90],
374                     rotationStep: 45,
375                     gridSize: 2,
376                     shape: ‘pentagon‘,
377                     maskImage: maskImage,
378                     drawOutOfBound: false,
379                     textStyle: {
380                         normal: {
381                             color: function () {
382                                 return ‘rgb(‘ + [
383                                     Math.round(Math.random() * 160),
384                                     Math.round(Math.random() * 160),
385                                     Math.round(Math.random() * 160)
386                                 ].join(‘,‘) + ‘)‘;
387                             }
388                         },
389                         emphasis: {
390                             shadowBlur: 10,
391                             shadowColor: ‘#333‘
392                         }
393                     },
394                     data: data.sort(function (a, b) {
395                         return b.value  - a.value;
396                     })
397                 } ]
398             };
399
400             maskImage.onload = function () {
401                 option.series[0].maskImage
402                 chart.setOption(option);
403             }
404
405             maskImage.src = ‘../img/test.png‘;
406
407             window.onresize = function () {
408                 chart.resize();
409             }
410
411         </script>
412     </body>
413 </html>

自定义照片

 JAR包下载地址:

https://github.com/Smartisa/JAR

原文地址:https://www.cnblogs.com/smartisn/p/12271968.html

时间: 2024-10-07 13:51:24

Echart 词云图 上手代码 同含(echarts-wordcloud.js)最简单的教程 复制可用的相关文章

Note of Jieba ( 词云图实例 )

Note of Jieba jieba库是python 一个重要的第三方中文分词函数库,但需要用户自行安装. 一.jieba 库简介 (1) jieba 库的分词原理是利用一个中文词库,将待分词的内容与分词词库进行比对,通过图结构和动态规划方法找到最大概率的词组:除此之外,jieba 库还提供了增加自定义中文单词的功能. (2) jieba 库支持3种分词模式: 精确模式:将句子最精确地切开,适合文本分析. 全模式:将句子中所以可以成词的词语都扫描出来,速度非常快,但是不能消除歧义. 搜索引擎模

python根据文本生成词云图

python根据文本生成词云图 效果 代码 from wordcloud import WordCloud import codecs import jieba #import jieba.analyse as analyse from scipy.misc import imread import os from os import path import matplotlib.pyplot as plt from PIL import Image, ImageDraw, ImageFont

【Python成长之路】词云图制作

[写在前面] 以前看到过一些大神制作的词云图 ,觉得效果很有意思.如果有朋友不了解词云图的效果,可以看下面的几张图(图片都是网上找到的): 网上找了找相关的软件,有些软件制作 还要付费.结果前几天在大神的公众号里的文章中看到了python也能实现,而且效果也很不错 .那还等什么,不赶紧盘它? [示例代码] 1 # coding=utf-8 2 # @Auther : "鹏哥贼优秀" 3 # @Date : 2019/7/31 4 # @Software : PyCharm 5 impo

寒假学习进度-11(词云图的使用)

1. 词云图属于 echarts 的扩展.如果想用 echarts 画词云图,需要另外引入 echarts-wordcloud.min.js.可以从 echarts 官网的下载->扩展下载中找到. 点进去就是字符云的 github 库,在这里下载 echarts-wordcloud.min.js 示例: <html> <head> <meta charset="utf-8"> <script src='https://cdn.bootcs

Echarts词云图

今天使用Echarts写了个词云图,之前使用pycharts生成的html就是echarts.主要代码如下,另外Echarts需要到https://www.echartsjs.com/下载,开发时使用.js文件即可. 先看效果: Echarts官网有详细的开发文档可以参考学习. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <titl

特朗普退出《巴黎协定》:python词云图舆情分析

1 前言 2017年6月1日,美国特朗普总统正式宣布美国退出<巴黎协定>.宣布退出<巴黎协定>后,特朗普似乎成了“全球公敌”. 特斯拉总裁马斯克宣布退出总统顾问团队 迪士尼董事长离开总统委员会 谷歌等25家大公司联名刊发整版广告:美国不应退出巴黎协定 法国总统马克龙:特朗普宣布退出<巴黎协定>是“错误”之举 …… 在此背景下,本文以python词云图分析的方式来了解下相关情况. 2 特朗普演讲内容分析 首先来看下特朗普宣布退出<巴黎协定>时都说了啥. 特朗普

用词云图分析一带一路峰会哪3个词说的最多

前言 最近几日关注度最高的新闻莫过于一带一路峰会相关的消息,会议结束后,一带一路峰会联合公告已经公布出来了.本文通过词云分析,了解本次公告以及习大大在峰会开幕式上主要都讲了哪些关键内容. 1 一带一路峰会联合公告词云图 5月17日公布的一带一路峰会联合公告的词云分析结果图,如下: 词云图上,字体越大表示该词语在文件中出现的次数越多. 从上图可以看出,出现次数最多的3个词语为“合作”.“我们”以及“加强” ,基本可以看出,本次峰会是一个新的起点,今后需要做的事情还很多,需要各方务实合作,哈. 2

词云wordcloud类介绍&amp;python制作词云图&amp;词云图乱码问题等小坑

词云图,大家一定见过,大数据时代大家经常见,我们今天就来用python的第三方库wordcloud,来制作一个大数据词云图,同时会降到这个过程中遇到的各种坑, 举个例子,下面是我从自己的微信上抓的微信好友签名,制作的词云图:看来用的做多的还是"方得始终"啊 首先我们需要几个库,pip完了导入 1 import chardet #检测字符类型的类 2 from wordcloud import WordCloud #词云库 3 import matplotlib.pyplot as pl

python爬虫爬取QQ说说并且生成词云图,回忆满满!

Python(发音:英[?pa?θ?n],美[?pa?θɑ:n]),是一种面向对象.直译式电脑编程语言,也是一种功能强大的通用型语言,已经具有近二十年的发展历史,成熟且稳定.它包含了一组完善而且容易理解的标准库,能够轻松完成很多常见的任务.它的语法非常简捷和清晰,与其它大多数程序设计语言不一样,它使用缩进来定义语句. Python支持命令式程序设计.面向对象程序设计.函数式编程.面向切面编程.泛型编程多种编程范式.与Scheme.Ruby.Perl.Tcl等动态语言一样,Python具备垃圾回收