<template>
<div>
<button @click="changeData(1)">切换数据1</button>
<button @click="changeData(2)">切换数据2</button>
<button @click="noData">没有数据</button>
<VenChart
:option="option"
:emptyOption="{
text: '亲,没有数据哦!',
style: {
fontSize: '24px',
fontWeight: 800,
},
}"
></VenChart>
<VenChart :option="option">
<template v-slot:empty> 自定义空内容</template>
</VenChart>
</div>
</template>
<script>
export default {
data() {
return {
option: {
title: {
text: "ECharts 入门示例",
},
tooltip: {},
xAxis: {
data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"],
},
yAxis: {},
series: [
{
name: "销量",
type: "bar",
data: [5, 20, 36, 10, 10, 20],
},
],
},
};
},
methods: {
changeData(type) {
this.option.series[0].data =
type === 1 ? [20, 16, 26, 18, 3, 15] : [8, 10, 13, 20, 22, 16];
},
noData() {
this.option.series[0].data = [];
},
},
};
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55