2025-05-15 14:57:30 +08:00

122 lines
2.5 KiB
Vue

<template>
<custom-echart-bar :chart-data="state.data" height="100%" :option="state.option" />
</template>
<script setup>
import { reactive, watch } from 'vue';
import { isEmpty } from '@/utils';
const props = defineProps({
data: {
type: Array,
default: () => [],
},
});
const state = reactive({
data: [],
option: {
grid: {
left: '5%',
right: '5%',
bottom: '5%',
top: '10%',
containLabel: true,
},
tooltip: {
className: 'custom-tooltip-container',
trigger: 'axis',
axisPointer: {
type: 'shadow',
},
backgroundColor: 'rgba(0,0,0,0.6);',
borderColor: '#35d0c0',
formatter: (data) => {
const params = data[0];
let str = `<div class="custom-echarts-tips" >
<span>${params.name}</span><br/>
<span>${params.marker} ${params.data} 万亩</span>
</div>`;
return str;
},
extraCssText: 'backdrop-filter: blur(8px);',
},
barStyle: {
barWidth: 14,
itemStyle: {
borderWidth: 14,
borderRadius: [8, 8, 8, 8], // 设置柱子的圆角半径
},
color: {
type: 'linear',
x: 1,
y: 0,
x2: 0,
y2: 0,
colorStops: [
{ offset: 0, color: '#35D0C0' },
{ offset: 1, color: 'rgba(53,208,192,0)' },
],
global: false,
},
},
xAxis: {
type: 'value',
splitLine: {
show: false,
lineStyle: {
type: 'dashed',
color: '#E5E5E5',
},
},
axisLabel: {
show: false,
textStyle: {
color: '#424242',
},
},
show: false,
axisLine: {
show: true,
},
axisTick: {
show: false,
},
},
yAxis: {
type: 'category',
data: ['耿马镇', '勐撒镇', '勐永镇', '孟定镇', '勐简乡', '贺派乡', '四排山乡', '芒洪乡', '大兴乡'],
axisTick: {
show: false,
},
splitLine: {
show: false,
},
axisLine: {
show: false,
},
},
series: [
{
type: 'bar',
// barWidth: '40%', // 设置柱的宽度
// barMinHeight: 2, // 设置柱的最小高度
// barGap: '20%', // 设置柱之间的间隙
},
],
},
});
watch(
() => props.data,
(val) => {
if (!isEmpty(val)) {
state.data = val;
}
},
{
deep: true,
immediate: true,
}
);
</script>