You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
3.1 KiB
104 lines
3.1 KiB
/*
|
|
* @Author: your name
|
|
* @Date: 2021-12-16 14:41:25
|
|
* @LastEditTime: 2021-12-17 10:21:38
|
|
* @LastEditors: Please set LastEditors
|
|
* @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
|
* @FilePath: /data-show/src/utils/gol/bubbleWord.js
|
|
*/
|
|
|
|
// let maskImage = new Image();
|
|
// maskImage.src = require('@/assets/images/carSide.png');
|
|
let colors = ['rgba(84,111,197,1)', 'rgba(145,203,116,1)', 'rgba(90,203,156,1)', 'rgba(248,200,87,1)', 'rgba(237,101,101,1)', "rgba(114,191,222,1)", 'rgba(58,162,114,1)', 'rgba(251,131,81,1)']
|
|
//报纸的样式
|
|
function newspaper() {
|
|
// let colorArr = ['#423312', '#605030', '#9A855B', '#DFC8A4'];
|
|
let colorArr = ['#FFF','#3373CC','#CC9D12','#54BF93']
|
|
let colorIndex = Math.ceil(Math.random() * 3);
|
|
return colorArr[colorIndex];
|
|
}
|
|
// 多彩的样式
|
|
function colorfulStyle() {
|
|
return 'rgb(' + [
|
|
Math.round(Math.random() * 255),
|
|
Math.round(Math.random() * 255),
|
|
Math.round(Math.random() * 255)
|
|
].join(',') + ')';
|
|
}
|
|
// 将后台数据转成数组
|
|
function doWordCloud(data) {
|
|
let arr1 = [];
|
|
for (let key in data) {
|
|
let obj = { name: key, value: data[key] };
|
|
arr1.push(obj);
|
|
}
|
|
return arr1;
|
|
}
|
|
//创建词云
|
|
export default function createWordCloud(data) {
|
|
let showData = null;
|
|
if (Array.isArray(data)) {
|
|
let words = [];
|
|
data.forEach(e => {
|
|
let o = {
|
|
name: e.key,
|
|
value: e.value
|
|
}
|
|
words.push(o)
|
|
})
|
|
showData = words;
|
|
} else {
|
|
let words = doWordCloud(data);
|
|
showData = words;
|
|
}
|
|
return {
|
|
tooltip: {
|
|
trigger: "axis",
|
|
backgroundColor: "#08182F",
|
|
color: "#fff",
|
|
borderColor: "#3373CC",
|
|
textStyle: {
|
|
color: "#fff", //设置文字颜色
|
|
fontSize: 9
|
|
},
|
|
extraCssText: "box-shadow: 0px 0px 10px 0px #3373CC;",
|
|
confine: true
|
|
},
|
|
series: [{
|
|
type: 'wordCloud',
|
|
shape: 'circle',
|
|
// rotationRange: [0, 0], //旋转角度的范围
|
|
rotationStep: 90, //旋转角度的步长
|
|
shape: 'circle',
|
|
sizeRange: [6, 48], //字体大小范围
|
|
gridSize: 8, //字间距
|
|
// maskImage: maskImage,
|
|
left: 'center',
|
|
top: 'center',
|
|
right: null,
|
|
bottom: null,
|
|
width: '100%',
|
|
height: '100%',
|
|
drawOutOfBound: true,
|
|
textStyle: {
|
|
fontFamily: 'sans-serif',
|
|
fontWeight: 'bold',
|
|
//颜色的回调函数, []
|
|
color: function() {
|
|
return newspaper()
|
|
}
|
|
},
|
|
emphasis: {
|
|
textStyle: {
|
|
shadowBlur: 100,
|
|
shadowColor: '#333'
|
|
}
|
|
},
|
|
data: showData
|
|
// {
|
|
// name: 'Sam S Club',
|
|
// value: 10000,
|
|
// }
|
|
}]
|
|
}
|
|
} |