Files
fengjie-datascreen/src/views/sentiment/components/wordCloud.vue
duanliang 5c17235581 新版式
2025-11-24 23:17:46 +08:00

63 lines
1.7 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<div class="wordCloud" :id="id" />
</template>
<script setup>
import 'echarts-wordcloud'
import { fitChartSize } from '@/utils/dataUtil'
import { getHotWordApi } from '@/api/sentiment'
import { useEchart } from '@/hooks/echart'
const { id, setOption } = useEchart()
const initChart = async () => {
let res = await getHotWordApi()
setOption({
series: [
{
type: 'wordCloud',
// 网格大小,各项之间间距
gridSize: fitChartSize(50),
// 形状 circle 圆cardioid 心, diamond 菱形,
// triangle-forward 、triangle 三角star五角星
shape: 'circle',
// 字体大小范围
sizeRange: [fitChartSize(14), fitChartSize(36)],
// 文字旋转角度范围
rotationRange: [0, 0],
// 旋转步值
rotationStep: 90,
// 自定义图形
// maskImage: maskImage,
left: 'center',
top: 'center',
// 画布宽
width: '100%',
// 画布高
height: '100%',
// 是否渲染超出画布的文字
drawOutOfBound: false,
textStyle: {
color: function () {
const colors = ['#165DFF', '#6aca37', '#05a4b6', '#f93920', '#f0b114']
return colors[parseInt(Math.random() * colors.length)]
},
padding: fitChartSize(10),
backgroundColor: 'rgba(0,255,255,.2)'
},
data: res.data
}
]
})
}
onMounted(() => {
initChart()
})
</script>
<style scoped lang="scss">
.wordCloud {
width: 100%;
height: 80%;
}
</style>