<template>
    <div class='app-container'>
        <div ref="echartsRef" id="main" style="width: 100%;height:400px;"></div>
    </div>
</template>

<script setup lang='ts'>
import { onMounted } from 'vue'
import { statUser } from '@/services/api/statistics/index'
import * as echarts from 'echarts';

onMounted(() => {
    let myChart = echarts.init(document.getElementById('main') as any);
    var option: any;
    var xData: any = []
    var yData: any = []
    statUser().then((res: any) => {
        if (res.code === 200) {
            res.data.rows.forEach((item: any) => {
                xData.push(item.day)
                yData.push(item.users)
            })
        }
    })
    option = {
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow'
            }
        },
        xAxis: {
            type: 'category',
            data: xData
        },
        yAxis: {},
        series: [
            {
                data: yData,
                type: 'bar',
                name: '用户增长量',
                label: {
                    show: true,
                    position: 'inside'
                },
            }
        ],
        legend: {
            show: true
        }
    };

    setTimeout(() => {
        option && myChart.setOption(option);
    }, 50)
})

</script>
 
<style lang = "scss" scoped>
</style>