< template> < div> < div> 【关键词条】< / div> < div ref= "target" class = "w-full h-full" style= 'width:300px;height:300px' > < / div> < / div>
< / template> < script setup>
import { ref, onMounted, watch } from 'vue' ;
import * as echarts from "echarts" ;
import 'echarts-wordcloud'
let myChart = null ;
const target = ref ( null ) ;
onMounted ( ( ) => { myChart = echarts. init ( target. value) ; renderChart ( ) ;
} ) ;
const randowRGB = ( ) => { const r = Math. floor ( Math. random ( ) * 255 ) const g = Math. floor ( Math. random ( ) * 255 ) const b = Math. floor ( Math. random ( ) * 255 ) return ` rgb( ${ r} , ${ g} , ${ b} ) `
}
const renderChart = ( ) => { const options = { series : [ { type : 'wordCloud' , sizeRange : [ 8 , 46 ] , rotationRange : [ 0 , 0 ] , gridSize : 0 , layoutAnimation : true , textStyle : { color : randowRGB} , emphasis : { textStyle : { fontWeight : 'bold' , color : '#ffffff' } } , data : [ { "value" : 36 , "name" : "企联网" } , { "value" : 14 , "name" : "智农通" } , { "value" : 39 , "name" : "OPPO" } , { "value" : 38 , "name" : "HONOR" } , { "value" : 26 , "name" : "红米" } , { "value" : 44 , "name" : "小米" } , { "value" : 37 , "name" : "美图" } , { "value" : 39 , "name" : "ONEPLUS" } , { "value" : 12 , "name" : "魅族" } , { "value" : 32 , "name" : "红手指" } , { "value" : 34 , "name" : "SAMSUNG" } , { "value" : 11 , "name" : "金立" } , { "value" : 20 , "name" : "BLACKBERRY" } , { "value" : 22 , "name" : "诺基亚" } , { "value" : 13 , "name" : "锤子" } , { "value" : 27 , "name" : "大疆" } , { "value" : 14 , "name" : "361" } , { "value" : 25 , "name" : "摩托罗拉" } , { "value" : 30 , "name" : "联想" } , { "value" : 27 , "name" : "玩家国度" } ] }
] } myChart. setOption ( options) ;
} ;
watch ( ( ) => data, renderChart)
< / script> < style lang= "scss" scoped> < / style>