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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
| <template>
| <div class="box-container" id="echarts40"></div>
| </template>
|
| <script>
| let timer = null;
| export default {
| data() {
| return {
| option: {},
| myChart: {},
| currentIndex: -1,
| lineData: [], // 添加用于存储饼图数据的属性
| };
| },
| mounted() {
| this.myChart = this.$echarts.init(document.getElementById("echarts40"));
|
| // 生成假数据
| this.generateFakeData();
|
| this.option = {
| tooltip: {
| trigger: 'item' // 修改为 'item' 以适应饼图
| },
| series: [{
| name: '状态数据',
| type: 'pie', // 修改为 'pie'
| radius: '50%',
| data: this.lineData.map(item => ({
| name: item.time, // 饼图中的每一项名称
| value: item.value // 对应的数值
| })),
| emphasis: {
| itemStyle: {
| shadowBlur: 10,
| shadowOffsetX: 0,
| shadowColor: 'rgba(0, 0, 0, 0.5)'
| }
| }
| }]
| };
|
| this.myChart.setOption(this.option);
| const that = this;
| window.addEventListener("resize", () => {
| that.myChart.resize();
| });
| },
| methods: {
| generateFakeData() {
| // 生成 4 个假数据点
| const fakeData = [];
| for (let i = 0; i < 4; i++) {
| fakeData.push({
| time: `数据${i + 1}`,
| value: Math.floor(Math.random() * 100) + 1 // 随机生成 1-100 的值
| });
| }
| this.lineData = fakeData;
| },
|
| },
| };
| </script>
|
| <style>
| #echarts40 {
| width: 3.84rem;
| }
| </style>
|
|