艺术家
2025-06-09 7c129cb1793c51db134afef96dc099b62144dca3
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<template>
  <el-card style="border-radius: 0" :body-style="{ padding: '1rem 2rem' }" v-loading="loading">
    <template #header>
      <div style="font-weight: bold; font-size: 1.2rem">维保统计</div>
    </template>
    <div ref="chartDom" style="height: 25rem; width: 100%"></div>
  </el-card>
</template>
 
<script setup>
import { ref, onMounted, onUnmounted, nextTick } from "vue";
// 引入echarts
import * as echarts from "echarts";
import { GetMaintenanceDistApi } from "../../api/dashboard";
import { ElLoading } from 'element-plus'
const loading=ref(true)
// 创建一个响应式引用来保存DOM元素
const chartDom = ref(null);
let chartInstance = null;
 
const xData = ref([])
const yData = ref([])
 
 
// 初始化ECharts实例并设置配置项(这里以折线图为例,但可灵活替换)
onMounted(async () => {
  await GetMaintenanceDistApi().then(res => {
    xData.value = res.data.map(i=>i.year)
    yData.value = res.data.map(i=>i.sumCount)
  })
 
 
  await nextTick(); // 确保DOM已经渲染完成
  chartInstance = echarts.init(chartDom.value);
 
  const option = {
    // backgroundColor: "#0f375f",
    grid: {
      top: "20%",
      bottom: "10%", //也可设置left和right设置距离来控制图表的大小
      left: "7%",
      right: 0,
    },
    tooltip: {
      trigger: "axis",
      axisPointer: {
        type: "shadow",
        label: {
          show: true,
        },
      },
    },
    legend: {
      data: ["维保数量"],
      top: "0%",
      right: "0%",
      textStyle: {
        color: "#000",
      },
    },
    xAxis: {
      data: xData.value,
      axisLine: {
        show: true, //隐藏X轴轴线
        lineStyle: {
          color: "#000",
        },
      },
      axisTick: {
        show: true, //隐藏X轴刻度
      },
      axisLabel: {
        show: true,
        textStyle: {
          color: "#000", //X轴文字颜色
        },
      },
    },
    yAxis: [
      {
        type: "value",
        minInterval:1,
        name: "件",
        nameTextStyle: {
          color: "#000",
        },
        splitLine: {
          show: false,
        },
        axisTick: {
          show: true,
        },
        axisLine: {
          show: true,
          lineStyle: {
            color: "#666",
          },
        },
        axisLabel: {
          show: true,
          textStyle: {
            color: "#666",
          },
        },
        splitLine: {
          // 网格线
          show: true,
          lineStyle: { //分割线
            color: "#eee",
            width: 1,
            type: "dashed" //dotted:虚线 solid:实线
          }
        },
      },
      {
        type: "value",
        gridIndex: 0,
        min: 50,
        max: 100,
        splitNumber: 8,
        splitLine: {
          show: false,
        },
        axisLine: {
          show: false,
        },
        axisTick: {
          show: false,
        },
        axisLabel: {
          show: false,
        },
        splitArea: {
          show: true,
          areaStyle: {
            color: ["rgba(250,250,250,0.0)", "rgba(250,250,250,0.05)"],
          },
        },
      },
    ],
    series: [
      // {
      //   name: "维保数量",
      //   type: "line",
      //   barWidth: 15,
      //   itemStyle: {
      //     normal: {
      //       color: "#ff3333"
      //     },
      //   },
      //   data: yData.value,
      // },
      {
        name: "维保数量",
        type: "bar",
        barWidth: 15,
        itemStyle: {
          normal: {
            color: "#0099ff"
          },
        },
        data: yData.value,
      },
    ],
  };
  chartInstance.setOption(option);
  nextTick(() => {
    loading.value = false;
  })
});
 
// 销毁ECharts实例
onUnmounted(() => {
  if (chartInstance != null && chartInstance.dispose) {
    chartInstance.dispose();
  }
});
 
//窗口大小变化重绘echart
window.onresize = function () {
  if (chartInstance != null && chartInstance.resize) {
    chartInstance.resize();
  }
};
</script>
 
<style></style>