<template>
  <div ref="chartRef" :style="{ height, width }"></div>
</template>
<script lang="ts">
import { PropType, Ref, defineComponent, onMounted, ref } from 'vue';
import { useECharts } from '/@/hooks/web/useECharts';
import { yearStatisticChart } from '../../StRectifyStaticsChart.api';

export default defineComponent({
  props: {
    width: {
      type: String as PropType<string>,
      default: '100%',
    },
    height: {
      type: String as PropType<string>,
        default: 'calc(100vh - 250px)',
    },
  },
  setup() {
    const chartRef = ref<HTMLDivElement | null>(null);
    const { setOptions } = useECharts(chartRef as Ref<HTMLDivElement>);
    onMounted(() => {
      yearStatisticChart({}).then(rep=>{
        if(!rep || rep.names==null||rep.names.length==0){
          return
        }
      setOptions({
        title: {
          text: ''
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          }
        },
        legend: {},
        grid: {
          top: '10%',
          left: '15%',
          right: '5%',
          bottom: '10%',
          containLabel: false
        },
        xAxis: {
          type: 'category',
          data: rep.names||[]
        },
        yAxis: {
          type: 'value',
          boundaryGap: [0, 0.01],
          max: 100,
          axisLabel: {
            formatter: '{value} %',
          }
        },
        series: [
          {
            type: 'bar',
            label: {
              show: true,
              position: 'top',
              formatter: '{c}%'
            },
            data: rep.values||[]
          },
        ]
      })
    })
    })
    return { chartRef }
  },
})
</script>
