<template>
  <div class="chart" :id="id"></div>
</template>

<script lang="ts">
import { Component, Prop, Vue, Watch } from 'vue-property-decorator'
import * as echarts from 'echarts';
type EChartsOption = echarts.EChartsOption;

@Component
export default class Line01 extends Vue {
  id=this.randomString();

  mounted(){
    this.init()
  }

  randomString(){
    const str = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    let result = '';
    for (let i = 10; i > 0; --i) 
      result += str[Math.floor(Math.random() * str.length)];
    return result;
  }
  init(){
    let chartDom:any = document.getElementById(this.id);
    let myChart = echarts.init(chartDom);
    let option: EChartsOption;

    option = {
      title: {
        text: '每月成交量和退货量',
      },
      tooltip: {
        trigger: 'axis'
      },
      legend: {
        data: ['成交量', '退货量',]
      },
      grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
      },
      toolbox: {
        feature: {
          // saveAsImage: {}
        }
      },
      xAxis: {
        type: 'category',
        boundaryGap: false,
        data: ['2022/08', '2022/09', '2022/10', '2022/11', '2022/12', '2023/01','2023/02','2023/03','2023/04','2023/05','2023/06','2023/07']
      },
      yAxis: {
        type: 'value'
      },
      series: [
        {
          name: '成交量',
          type: 'line',
          data: [0, 0, 0, 0, 0, 0, 0, 0,70,380,500, 580]
        },
        {
          name: '退货量',
          type: 'line',
          data: [0, 0, 0, 0, 0, 0, 0, 0,10,40,50, 62]
        }
      ]
    };

    option && myChart.setOption(option);
  }
}
</script>

<style lang="scss" scoped>
.chart{
  height: 100%;
  width: 100%;
}
</style>