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>
|
|
|
|
</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: []
|
|
|
|
},
|
|
|
|
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,
|
|
|
|
top: 10
|
|
|
|
},
|
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>
|
|
|
|
</style>
|