<template>
    <div class="person_box">
        <div ref="chartRouting" style="width: 100%;height: 100%;"></div>
    </div>
</template>

<script setup>
import * as echarts from 'echarts'
const props = defineProps({
    resultData: {
        type: Array,
        default: []
    }
})

const chartRouting = ref(null);
let chartInstance = null;
const initChart = () => {
    let result = props.resultData
    chartInstance = echarts.init(chartRouting.value);
    chartInstance.setOption({
        grid: {
            left: '4%',
            right: '4%',
            bottom: '10%',
            top: '16%',
            containLabel: true,
        },
        xAxis: {
            data: result.map((item) => item.time),
            type: 'category',
            boundaryGap: false,
            axisLine: {
                symbol: 'none',
                lineStyle: {
                    color: '#50637A',
                },
            },
            axisTick: {
                show: false,
            },
            axisLabel: {
                color: '#ffffff',
                fontSize: 12,
                padding: [10, 0, 0, 0],
            },
        },
        yAxis: {
            type: 'value',
            axisLabel: {
                color: '#ffffff',
                fontSize: 12,
                padding: [0, 10, 0, 0],
            },
            splitLine: {
                show: false,
            },
        },
        series: [
            {
                name: '时段',
                data: result.map((item) => item.value),
                type: 'line',
                smooth: true,
                color: '#00F7FF',
                lineStyle: {
                    width: 2,
                },
                areaStyle: {
                    color: new echarts.graphic.LinearGradient(
                        0,
                        0,
                        0,
                        1,
                        [{
                            offset: 0,
                            color: 'rgba(0, 247, 255, .6)',
                        },
                        {
                            offset: 0.8,
                            color: 'rgba(0, 247, 255, .2)',
                        },
                        ],
                        false
                    ),
                    shadowColor: 'rgba(0, 0, 0, 0.1)',
                    shadowBlur: 10,
                },
                symbol: 'circle',
                symbolSize: 6,
            },
        ],
    });
};
// 生命周期
onMounted(() => {
    initChart()
});
// 窗口自适应
window.addEventListener('resize', () => {
    chartInstance?.resize();
});
</script>

<style scoped lang="scss">
.person_box {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
}
</style>