<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'

// eslint-disable-next-line no-unused-vars
const animationDuration = 6000

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '475px'
    }
  },
  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.setOption({
        legend: {},
        tooltip: {},
        dataset: {
          source: [
            ['product', '2015', '2016', '2017'],
            ['10月', 43.3, 85.8, 93.7],
            ['9月', 83.1, 73.4, 55.1],
            ['8月', 86.4, 65.2, 82.5],
            ['7月', 72.4, 53.9, 39.1]
          ]
        },
        xAxis: [
          { type: 'category', gridIndex: 0, name: '最近12个月' }
        ],
        yAxis: [
          { gridIndex: 0, name: '总费用' }
        ],
        grid: [
          { bottom: '58%' },
          { top: '58%' }
        ],
        series: [
          { type: 'bar' },
          { type: 'bar' },
          { type: 'bar' }
        ]
      })
    }
  }
}
</script>
