echarts实现词云

编程入门 行业动态 更新时间:2024-10-23 13:27:13

<a href=https://www.elefans.com/category/jswz/34/1767945.html style=echarts实现词云"/>

echarts实现词云

最终效果图

实现思路:
1、前端引入echarts.min.js和echarts-wordcloud.js
实现:
前端代码:

<body><section class="mainBox"><div class="column"><div class="panel bar"><h2>词云</h2><div class="charts"></div><div class="pane-footer"></div></div></div></section><script src=".0.0.min.js"></script><script src="./js/flexble.js"></script>//到官网下载并引入echarts<script src='@5/dist/echarts.min.js'></script>//这里做词云图时需要<script src='./js/echarts-wordcloud.js'></script>//引入js代码<script src="./js/index.js"></script>
</body>

js部分(这里的js的内容就是index.js文件里的内容)


(function(data){var chart = echarts.init(document.querySelector('.bar .charts'));$.get('./weibo_hot_word.json',function(data){//引入本地json文件console.log("data")console.log(data)var bseries=[];data.map(item=>{console.log("item")bseries.push({'name':item.word,'value': item.weight})console.log(bseries)})option = {tooltip: {},series: [ {type: 'wordCloud',gridSize: 2,sizeRange: [12, 50],rotationRange: [-90, 90],shape: 'pentagon',width: 1000,height: 1000,drawOutOfBound: true,textStyle: {color:function () {return 'rgb(' + [Math.round(Math.random() * 160),Math.round(Math.random() * 160),Math.round(Math.random() * 160)].join(',') + ')';}},emphasis: {textStyle: {shadowBlur: 10,shadowColor: '#333'}},data:bseries,}]}chart.setOption(option);})

注意:在vscode中运行index.html文件是,应该运行到open with live server,不然$.get()会出现跨域问题。

更多推荐

echarts实现词云

本文发布于:2024-02-10 15:35:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1676072.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:echarts

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!