91 lines
1.9 KiB
Vue
91 lines
1.9 KiB
Vue
<script setup lang="ts">
|
|
import { ref } from 'vue';
|
|
import { useEcharts } from '@/hooks/common/echarts';
|
|
|
|
defineOptions({
|
|
name: 'RingChart'
|
|
});
|
|
|
|
const props = defineProps<{ data: { name: string; value: number; }[]; }>();
|
|
|
|
const { domRef, updateOptions } = useEcharts(() => ({
|
|
tooltip: {
|
|
trigger: "axis",
|
|
axisPointer: {
|
|
type: "shadow",
|
|
textStyle: {
|
|
color: "#fff",
|
|
},
|
|
},
|
|
},
|
|
legend: {
|
|
show:false,
|
|
bottom: '20%',
|
|
left: 'center',
|
|
icon: 'circle',
|
|
itemWidth: 10,
|
|
itemHeight: 10,
|
|
itemStyle: {
|
|
borderWidth: 0
|
|
},
|
|
},
|
|
grid: {
|
|
top: "5%",
|
|
left: "5%",
|
|
right: "5%",
|
|
bottom: "11%",
|
|
},
|
|
calculable: true,
|
|
xAxis: [
|
|
{
|
|
type: "category",
|
|
boundaryGap: true, // 新增,固定柱子位置
|
|
axisLine: {
|
|
show: false,
|
|
},
|
|
axisLabel: {
|
|
interval: 0,
|
|
},
|
|
splitLine: { show: false },
|
|
axisTick: { show: false },
|
|
splitArea: { show: false },
|
|
data: [] as string[],
|
|
},
|
|
],
|
|
yAxis: [
|
|
{
|
|
type: "value",
|
|
show: false,
|
|
},
|
|
],
|
|
series: [
|
|
{
|
|
type: "bar",
|
|
barWidth: 45,
|
|
barGap: "10%",
|
|
color: "#2080f0",
|
|
label: { show: true, position: 'top',color: '#333',fontWeight: 'bold' },
|
|
data: [] as number[],
|
|
},
|
|
]
|
|
}));
|
|
|
|
function init() {
|
|
updateOptions(opts => {
|
|
let allMonth = props.data.map((item:any) => item.name);
|
|
let values = props.data.map((item:any) => item.value);
|
|
opts.xAxis[0].data = allMonth;
|
|
opts.series[0].data = values;
|
|
return opts;
|
|
});
|
|
}
|
|
|
|
init();
|
|
</script>
|
|
|
|
<template>
|
|
<div ref="domRef" class="w-full h-220px overflow-hidden"></div>
|
|
</template>
|
|
|
|
<style scoped></style>
|