<template>
  <div ref="chartRef" :style="{ height, width }"></div>
</template>
<script lang="ts">
  import { basicProps } from './props';
</script>
<script lang="ts" setup>
  import { onMounted, ref, Ref } from 'vue';
  import { useECharts } from '/@/hooks/web/useECharts';
  defineProps({
    ...basicProps,
  });

  const chartRef = ref<HTMLDivElement | null>(null);
  const { setOptions } = useECharts(chartRef as Ref<HTMLDivElement>);
  onMounted(() => {
    setOptions({
      tooltip: {
        trigger: 'axis',
        axisPointer: {
          lineStyle: {
            width: 1,
            color: '#019680',
          },
        },
      },
      legend: {
        x: 'center',
        y: 'bottom',
      },
      grid: { left: '1%', right: '1%', top: '2%', bottom: '10%', containLabel: true },
      xAxis: {
        type: 'category',
        data: [...new Array(30)].map((_item, index) => `${index + 1}日`),
      },
      yAxis: {
        type: 'value',
        max: 8000,
        splitNumber: 4,
      },
      series: [
        {
          data: [3000, 2000, 3333, 5000, 3200, 4200, 3200, 2100, 3000, 5100, 6000, 3200, 4800],
          type: 'bar',
          itemStyle: { normal: { color: '#38a0ff' } },
          barMaxWidth: 80,
          name: '用户浏览量',
        },
        {
          data: [100, 2000, 3333, 5000, 3200, 4200, 3200, 2100, 3000, 5100, 6000, 3200, 4800],
          type: 'bar',
          itemStyle: { normal: { color: '#4cca73' } },
          barMaxWidth: 80,
          name: '用户分享数',
        },
      ],
    });
  });
</script>
