<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', axisPointer: { lineStyle: { color: { type: 'linear', x: 0, y: 0, x2: 0, y2: 1, colorStops: [ { offset: 0, color: 'rgba(255,255,255,0)', // 0% 处的颜色 }, { offset: 0.5, color: 'rgba(255,255,255,1)', // 100% 处的颜色 }, { offset: 1, color: 'rgba(255,255,255,0)', // 100% 处的颜色 }, ], global: false, // 缺省为 false }, }, }, }, 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: { show: true, lineStyle: { type: 'dashed', color: '#1ba6ba', }, }, axisLine: { show: true, lineStyle: { color: '#fff', }, }, axisTick: { show: false, }, }, ], series: [ { name: '满意度%', type: 'bar', smooth: true, showSymbol: false, // symbolSize: 8, // zlevel: 3, barWidth: '30px', itemStyle: { normal: { label: { //柱体上显示数值 rotate: 30, // 设置倾斜角度 interval: 0, show: true, //开启显示 // position: 'center',//在上方显示 textStyle: { //数值样式 fontSize: '10px', color: '#fff', }, }, color: { type: 'linear', x: 0, //右 y: 0, //下 x2: 0, //左 y2: 1, //上 colorStops: [ { offset: 0, //offset表示位置【0,1】范围,0表示起始位置,1表示结束位置 color: '#124e86', // 起始位置设置此颜色,终止位置设置下面的颜色 }, { offset: 1, color: '#42a8fc', }, ], }, }, }, 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>