需求:展示出云彩状的词云
安装
npm install echarts
npm install echarts-wordcloud
词云安装官网 https://github.com/ecomfe/ech...
引入到当前页面
import React from 'react';
import 'echarts-wordcloud';
import echarts from 'echarts';
class Wordcloudl extends React.Component{
componentDidMount() {
var myChart = echarts.init(document.getElementById('wordcloudl'));
var maskImage = new Image();
//重点:云彩图片的base64码
maskImage.src = 'data:image/svg+xml;utf8;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pgo8IS0tIEdlbmVyYXRvcjogQWRvYmUgSWxsdXN0cmF0b3IgMTYuMC4wLCBTVkcgRXhwb3J0IFBsdWctSW4gLiBTVkcgVmVyc2lvbjogNi4wMCBCdWlsZCAwKSAgLS0+CjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+CjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiBpZD0iQ2FwYV8xIiB4PSIwcHgiIHk9IjBweCIgd2lkdGg9IjI1NnB4IiBoZWlnaHQ9IjI1NnB4IiB2aWV3Qm94PSIwIDAgNTQ4LjE3NiA1NDguMTc2IiBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCA1NDguMTc2IDU0OC4xNzY7IiB4bWw6c3BhY2U9InByZXNlcnZlIj4KPGc+Cgk8cGF0aCBkPSJNNTI0LjE4MywyOTcuMDY1Yy0xNS45ODUtMTkuODkzLTM2LjI2NS0zMi42OTEtNjAuODE1LTM4LjM5OWM3LjgxLTExLjk5MywxMS43MDQtMjUuMTI2LDExLjcwNC0zOS4zOTkgICBjMC0yMC4xNzctNy4xMzktMzcuNDAxLTIxLjQwO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ff',
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
series: [{
type: 'wordCloud',
gridSize: 1,
// Text size range which the value in data will be mapped to.
// Default to have minimum 12px and maximum 60px size.
sizeRange: [12, 55],
// Text rotation range and step in degree. Text will be rotated randomly in range [-90, 90] by rotationStep 45
rotationRange: [-45, 0, 45, 90],
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:'90%',
height:'110%',
data:[
{
name: 'Sam S Club',
value: 10000,
}, {
name: 'Macys',
value: 6181
}, {
name: 'Amy Schumer',
value: 4386
}, {
name: 'Jurassic World',
value: 4055
}, {
name: 'Charter Communications',
value: 2467
}, {
name: 'Chick Fil A',
value: 2244
}, {
name: 'Planet Fitness',
value: 1898
}, {
name: 'Pitch Perfect',
value: 1484
}, {
name: 'Express',
value: 1112
}, {
name: 'Home',
value: 965
}, {
name: 'Johnny Depp',
value: 847
}, {
name: 'Lena Dunham',
value: 582
}, {
name: 'Lewis Hamilton',
value: 555
}, {
name: 'KXAN',
value: 550
}, {
name: 'Point Break',
value: 265
}]
}]
})
}
}
render () {
return(
<div>
<div id='wordcloudl' style={{height:400}}></div>
</div>
)
}
}
export default Wordcloudl;
如果没有看懂还有更多的地方可以参考:
ecahrts形状不一的词云:https://download.csdn.net/dow...
基于ecahrts的词云:https://blog.csdn.net/u013808...
ecahrts字符云:https://blog.csdn.net/shelbya...
echarts之词云随机颜色的配置:https://blog.csdn.net/IT_1692...
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。