python词云自定义形状_echarts实现词云自定义形状

需求:展示出云彩状的词云

bVboyCS?w=575&h=310

安装

npm install echarts

npm install echarts-wordcloud

引入到当前页面

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+Cgk8cGF0aCBkPSJNNTI0LjE4MywyOTcuMDY1Yy0xNS45ODUtMTkuODkzLTM2LjI2NS0zMi42OTEtNjAuODE1LTM4LjM5OWM3LjgxLTExLjk5MywxMS43MDQtMjUuMTI2LDExLjcwNC0zOS4zOTkgICBjMC0yMC4xNzctNy4xMzktMzc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ption( {

backgroundColor:'#fff',

tooltip: {

pointFormat: '{series.name}: {point.percentage:.1f}%'

},

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(

)

}

}

export default Wordcloudl;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值