154 lines
3.0 KiB
Vue
154 lines
3.0 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: () => [],
|
|
},
|
|
query: {
|
|
type: String,
|
|
default: '',
|
|
},
|
|
});
|
|
|
|
const state = reactive({
|
|
data: [],
|
|
option: {
|
|
grid: {
|
|
left: '5%',
|
|
right: '5%',
|
|
bottom: '5%',
|
|
top: '10%',
|
|
containLabel: true,
|
|
},
|
|
tooltip: {
|
|
trigger: 'axis',
|
|
axisPointer: {
|
|
type: 'shadow',
|
|
},
|
|
backgroundColor: 'rgba(0,0,0,0.6);',
|
|
borderColor: '#35d0c0',
|
|
borderRadius: 8,
|
|
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: 10,
|
|
itemStyle: {
|
|
borderWidth: 10,
|
|
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,
|
|
}
|
|
);
|
|
|
|
watch(
|
|
() => props.query,
|
|
(val) => {
|
|
if (!isEmpty(val)) {
|
|
loadData(val);
|
|
}
|
|
},
|
|
{
|
|
deep: true,
|
|
immediate: true,
|
|
}
|
|
);
|
|
const loadData = (val) => {
|
|
if (val === 'all') {
|
|
state.data = props.data;
|
|
state.option.yAxis.data = ['耿马镇', '勐撒镇', '勐永镇', '孟定镇', '大兴乡'];
|
|
} else {
|
|
for (let i in props.data) {
|
|
if (val === props.data[i].name) {
|
|
state.data = [];
|
|
state.data.push(props.data[i]);
|
|
state.option.yAxis.data = [props.data[i].name];
|
|
}
|
|
}
|
|
}
|
|
console.log(val);
|
|
};
|
|
</script>
|