bt-xtgxq-population-bigdata/src/components/echarts/BarSpike.vue

112 lines
2.3 KiB
Vue
Raw Normal View History

2023-11-19 17:34:02 +08:00
<template>
2023-11-21 17:48:18 +08:00
<div class="bar-spike">
2023-11-19 17:34:02 +08:00
<div :id="domId" :style="{ width: w, height: h }"></div>
2023-12-14 14:22:56 +08:00
<div class="percent">
<ul>
<li v-for="item in pData" :key="item">{{ item }}</li>
</ul>
</div>
2023-11-19 17:34:02 +08:00
</div>
</template>
<script setup>
2023-11-25 17:18:28 +08:00
import { ref, defineProps, defineEmits, inject } from 'vue';
2023-11-19 17:34:02 +08:00
import { onMounted } from 'vue';
const props = defineProps({
id: String,
w: {
type: Number,
default: 200
},
h: {
type: Number,
default: 200
},
title: {
type: String,
default: '尖峰图'
},
xData: {
type: Array,
default: []
},
2023-12-14 14:22:56 +08:00
pData: {
type: Array,
default: []
},
2023-11-19 17:34:02 +08:00
data: {
type: Array,
default: []
}
});
2023-11-25 17:18:28 +08:00
const emits = defineEmits(['click']);
2023-11-19 17:34:02 +08:00
const echarts = inject('echarts');
const domId = ref(props.id);
const w = ref(`${props.w}px`);
const h = ref(`${props.h}px`);
const init = () => {
var chart = echarts.init(document.getElementById(domId.value));
chart.setOption({
title: {
text: props.title
},
tooltip: {},
2023-11-22 18:59:08 +08:00
grid: {
left: 50,
2023-12-14 14:22:56 +08:00
top: 10,
right: 100
2023-11-22 18:59:08 +08:00
},
2023-11-19 17:34:02 +08:00
xAxis: {
type: 'category',
data: props.xData
},
yAxis: {
type: 'value'
},
series: [{
type: 'pictorialBar',
barCategoryGap: '0%',
symbol: 'path://M0,10 L10,10 C5.5,10 5.5,5 5,0 C4.5,5 4.5,10 0,10 z',
itemStyle: {
opacity: 0.6
},
emphasis: {
itemStyle: {
opacity: 1
}
},
z: 10,
data: props.data,
}]
})
2023-11-25 17:18:28 +08:00
chart.on('click', (params) => {
emits('click', {
index: params.dataIndex,
name: props.xData[params.dataIndex],
value: props.data[params.dataIndex]
})
})
2023-11-19 17:34:02 +08:00
}
onMounted(() => {
init();
});
</script>
<style lang="stylus" scoped>
2023-12-14 14:22:56 +08:00
.bar-spike
position relative
.percent
font-size 12px
ul
position absolute
list-style none
top 0
right 0
li
width 100px
text-align end
2023-11-19 17:34:02 +08:00
</style>