<template> <div> <div ref="assetEchart" class="asset_echart"></div> </div> </template> <script setup> import { init } from 'echarts'; import 'echarts-liquidfill/src/liquidFill.js'; const assetEchart = ref(null); let { data: { xData, yData }, } = defineProps(['data']); const initM = () => { const chart = init(assetEchart.value); window.addEventListener('resize', () => { chart.resize(); }); chart.setOption({ grid: { top: 20, left: 0, bottom: 20, right: 40, containLabel: true, }, tooltip: { trigger: 'axis', }, xAxis: [ { type: 'category', boundaryGap: true, axisLabel: { margin: 5, formatter: '{value}', textStyle: { color: '#fff', }, }, axisLine: { lineStyle: { color: '#fff', }, }, data: xData, }, ], yAxis: [ { type: 'value', margin: 5, axisLabel: { textStyle: { color: '#fff', }, }, nameTextStyle: { color: '#fff', fontSize: 12, lineHeight: 40, }, splitLine: { lineStyle: { type: 'dashed', color: '#fff', }, }, axisLine: { show: true, lineStyle: { color: '#fff', }, }, axisTick: { show: false, }, }, ], series: [ { name: '满意度%', type: 'line', smooth: true, showSymbol: false, symbolSize: 8, zlevel: 3, lineStyle: { normal: { width: 2, color: '#fff', }, }, areaStyle: { normal: { color: '#fff ', }, }, data: yData, }, ], }); window.addEventListener( 'resize', () => { chart.resize(); }, false ); // false代表事件句柄在冒泡阶段执行 }; onMounted(() => { initM(); }); </script> <style lang="scss" scoped> .asset_echart { width: 100%; height: 260px; &_echart { width: 100%; height: 100%; } } </style>