本文主要是介绍echarts实现词云效果,可点击其中某个字符,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
效果图如下:
需引入以下两个js文件:
<!--echarts-->
<script src="./static/echarts/echarts.min.js"></script>
<script src="./static/echarts/echarts-wordcloud.min.js"></script>
核心实现代码如下:
mounted:function(){this.initChart();
}
initChart() {var myChart = echarts.init(document.getElementById('wordCloud'));const option = {title: {text: '',x: "center"},backgroundColor: "#fff",// tooltip: {// pointFormat: "{series.name}: <b>{point.percentage:.1f}%</b>"// },series: [{type: "wordCloud",//用来调整词之间的距离gridSize: 30,//用来调整字的大小范围// Text size range which the value in data will be mapped to.// Default to have minimum 12px and maximum 60px size.sizeRange: [14, 60],// Text rotation range and step in degree. Text will be rotated randomly in range [-90, 90] by rotationStep 45//用来调整词的旋转方向,,[0,0]--代表着没有角度,也就是词为水平方向,需要设置角度参考注释内容// rotationRange: [-45, 0, 45, 90],// rotationRange: [ 0,90],rotationRange: [0, 0],//随机生成字体颜色// maskImage: maskImage,textStyle: {normal: {color: function() {return ("rgb(" +Math.round(Math.random() * 255) +", " +Math.round(Math.random() * 255) +", " +Math.round(Math.random() * 255) +")");}}},//位置相关设置// Folllowing left/top/width/height/right/bottom are used for positioning the word cloud// Default to be put in the center and has 75% x 80% size.left: "center",top: "center",right: null,bottom: null,width: "200%",height: "200%",//数据data: this.echartsData}]};myChart.setOption(option);// 点击某个字myChart.on('click',function(params){console.log('myChart----click---:',params,'------',params.data)});}
echartsData: [{name: "十九大精神",value: 15000},{name: "两学一做",value: 10081},{name: "中华民族",value: 9386},{name: "马克思主义",value: 7500},{name: "民族复兴",value: 7500},{name: "社会主义制度",value: 6500},{name: "国防白皮书",value: 6500},{name: "创新",value: 6000},{name: "民主革命",value: 4500},{name: "文化强国",value: 3800},{name: "国家主权",value: 3000},{name: "武装颠覆",value: 2500},{name: "领土完整",value: 2300},{name: "安全",value: 2000},{name: "从严治党",value: 1900},{name: "现代化经济体系",value: 1800},{name: "国防动员",value: 1700},{name: "信息化战争",value: 1600},{name: "局部战争",value: 1500},{name: "教育",value: 1200},{name: "职业教育",value: 1100},{name: "兵法",value: 900},{name: "一国两制",value: 800},{name: "特色社会主义思想",value: 700},]
注意:id为wordCloud的div的height和width一定要设置,不然可能会显示不了词云。
这篇关于echarts实现词云效果,可点击其中某个字符的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!