<template>
    <hc-charts ref="charts" :option="chartsOption" />
</template>

<script setup>
import { onMounted, ref, watch } from 'vue'
import { getNumber, getRandom } from 'js-fast-way'

const props = defineProps({
    datas: {
        type: Object,
        default: () => ({}),
    },
})

//渲染完成
onMounted(() => {
    setClassifyChartsOption(props.datas)
})

//监听值变化
watch(() => props.datas, (val) => {
    setClassifyChartsOption(val)
})

//处理数据
const charts = ref(null)
const chartsOption = ref({})
const setClassifyChartsOption = (data) => {
    chartsOption.value = {
        backgroundColor: '',
        color: ['#BE8368', '#08818E'],
        tooltip: {
            trigger: 'axis',
        },
        legend: {
            top: '1',
            data: ['计划投资', '实际完成投资'],
        },
        grid: {
            top: '50',
            left: '10',
            right: '20',
            bottom: '5',
            containLabel: true,
        },
        xAxis: {
            type: 'category',
            boundaryGap: false,
            data: ['一季度', '二季度', '三季度', '四季度'],
        },
        yAxis: {
            type: 'value',
        },
        series: [
            {
                name: '计划投资',
                type: 'line',
                data: data?.a,
            },
            {
                name: '实际完成投资',
                type: 'line',
                data: data?.b,
            },
        ],
    }
}
</script>
