vue 使用 echarts 热词图
- 安装
npm install echarts@5.4.1 --save
npm install echarts-wordcloud@2.1.0 --save
- main.js
import echarts from 'echarts'
Vue.prototype.$echarts = echarts
import 'echarts-wordcloud'
- 使用
getChartData() {
const myChart = echarts.init(this.$refs.wordChart);
const option = {
series: [
{
type: 'wordCloud',
gridSize: 20,
sizeRange: [12, 50],
rotationRange: [-90, 90],
shape: 'pentagon',
textStyle: {
color: function () {
return (
'rgb(' + Math.round(Math.random() * 255) + ', ' + Math.round(Math.random() * 255) + ', ' + Math.round(Math.random() * 255) + ')'
);
},
/*
// 之前这样设置颜色不起作用
normal: {
color: function () {
return 'rgb(' + [
Math.round(Math.random() * 160),
Math.round(Math.random() * 160),
Math.round(Math.random() * 160)
].join(',') + ')';
}
},
*/
emphasis: {
shadowBlur: 10,
shadowColor: '#333',
},
},
data: [
{ name: 'java', value: 10000 },
{ name: 'javaScript', value: 6181 },
{ name: 'c++', value: 4386 },
{ name: 'php', value: 4055 },
],
},
],
};
myChart.setOption(option);
window.addEventListener('resize', function () {
myChart.resize();
});
},