<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'

const animationDuration = 3000

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '300px'
    },
    chartData: {
      type: Object,
      required: true
    }
  },
 watch: {
    chartData: {
      deep: true,
      handler(val) {
        this.setOptions(val)
      }
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons');
      this.chart = echarts.init(this.$el, 'macarons')
      this.setOptions(this.chartData)
    },
      setOptions({ y, x ,data } = {}) {
        console.log(y,x,data,56)
       this.chart.setOption({
                title: {
                       text: '折线图堆叠'
                   },
                   tooltip: {
                       trigger: 'axis'
                   },
                   legend: {
                       data: []
                   },
                   grid: {
                       left: '3%',
                       right: '4%',
                       bottom: '3%',
                       containLabel: true
                   },
                   toolbox: {
                       feature: {
                           saveAsImage: {}
                       }
                   },
                   color:['#47D737'],
                   xAxis: {
                       type: 'category',
                       boundaryGap: false,
                       axisLine: {
                         lineStyle: {
                           color: '#343434',
                           width: 1 //这里是为了突出显示加上的
                         }
                       },
                       data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
                   },
                   yAxis: {
                       type: 'value',
                       axisLine: {
                         lineStyle: {
                           color: '#343434',
                           width: 1 //这里是为了突出显示加上的
                         }
                       }
                   },
                   series: [
                       {
                           name: '视频广告',
                           type: 'line',
                           stack: '总量',
                           data: [150, 232, 201, 154, 190, 330, 410]
                       },
                   ]
             })
      }
  }
}
</script>
