<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 Bar02 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: '每月订单量',
        left: 'center'
      },
      xAxis: {
        type: 'category',
        data: ['7月', '8月', '9月', '10月', '11月', '12月', '1月','2月','3月','4月','5月','6月']
      },
      yAxis: {
        type: 'value'
      },
      series: [
        {
          data: [0, 0, 0, 0, 0, 0, 0, 0, 0,100,460,600],
          type: 'bar',
          showBackground: true,
          backgroundStyle: {
            color: 'rgba(180, 180, 180, 0.2)'
          },
          itemStyle: {
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
              { offset: 0, color: '#83bff6' },
              { offset: 0.5, color: '#188df0' },
              { offset: 1, color: '#188df0' }
            ])
          }
        }
      ]
    };

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

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