开头一定要引入这两个js,奇怪的是,3.3.2的echarts.js我下载下来之后词云就出不来了,所以暂时只能这样了,
<script src="https://cdn.bootcss.com/echarts/3.3.2/echarts.js"></script>
<script src='/resources/dist/worldcloud.js'></script>
<script type="text/javascript">
var myChart = echarts.init(document.getElementById('chart_wordCloud'));
$(function(){
echartsCloud();//初始化echarts图
})
function echartsCloud(){
// 基于准备好的dom,初始化echarts实例
myChart.setOption({
tooltip: {},
series: [{
name:'频率',
type : 'wordCloud', //类型为字符云
shape:'smooth', //平滑
gridSize : 2, //网格尺寸
size : ['80%','80%'],
sizeRange : [ 35, 100 ],
rotationRange : [ -50, 80 ], //旋转范围
textStyle : {
normal : {
fontFamily:'sans-serif',
color : function() {
return 'rgb('
+ [ Math.round(Math.random() * 160),
Math.round(Math.random() * 160),
Math.round(Math.random() * 160) ]
.join(',') + ')';
}
},
emphasis : {
shadowBlur : 5, //阴影距离
shadowColor : '#333' //阴影颜色
}
},
data:[],
}]
});
//异步加载数据
$.ajax({
type:"POST",
url:"/pcDocumentAction/wordCloud.action?view=json&time="+'30',
success:function(data){
myChart.setOption({
series: [{
data: data.obj
}]
});
}
});
};
function selectChange(){
var time=$("#select option:selected").val();
$.ajax({
type:"POST",
url:"/pcDocumentAction/wordCloud.action?view=json&time="+time,
success:function(data){
myChart.setOption({
series: [{
data: data.obj
}]
});
}
});
};
</script>