<template>
  <div class="disease-forecast">
    <div class="chart" ref="chart" />
    <Select class="custom-select" v-model="type">
      <Option v-for="item in options" :key="item" :value="item">{{item}}</Option>
    </Select>
  </div>
</template>

<script>
import echarts from 'echarts'
export default {
  name: 'DiseaseForecast',
  data() {
    return {
      type: '小龙虾',
      options: ['小龙虾'],
      chart: null,
      option: {
        tooltip: {
          trigger: 'axis',
        },
        grid: {
          top: '15%',
          left: '5%',
          right: '5%',
          bottom: '10%',
          width: 'auto',
          height: 'auto',
          containLabel: true,
        },
        xAxis: {
          type: 'category',
          boundaryGap: false,
          axisLine: {
            lineStyle: {
              color: 'rgba(91,213,255,0.1)'
            }
          },
          axisLabel: {
            textStyle: {
              color: '#ccc',
            },
            fontSize: this.fontSize,
          },
          data: ['2014', '2015', '2016', '2017', '2018', '2019', '2020'],
        },
        yAxis: {
          type: 'value',
          // name: '单位：个',
          max: 500,
          min: 0,
          interval: 100,
          axisLine: {
            show: false,
          },
          axisLabel: {
            textStyle: {
              color: '#fff',
            },
            fontSize: this.fontSize,
          },
          nameTextStyle: {
            color: '#ccc',
            fontSize: this.fontSize,
          },
          splitLine: {
            lineStyle: {
              color: 'rgba(91,213,255,0.1)'
            }
          },
        },
        series: [
          {itemStyle: {color: 'gold'}, areaStyle: {
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
              {offset: 0, color: 'rgba(255,215,0,0.8)'},
              {offset: 1, color: 'rgba(255,215,0,0.1)'}
            ])},
          smooth: true, type: 'line', data: [300, 280, 400, 380, 360, 320, 300]},
        ],
        dataZoom: [{
          start: 10,
          end: 80,
          backgroundColor: '#105179',
          fillerColor: '#46b9ef',
          borderColor: 'transparent',
          bottom: '2%',
          height: 10,
          borderRadius: 10,
          handleSize: '200%',
          handleStyle: {
            color: '#fff',
          },
          textStyle: {
            color: '#fff',
          },
        }],
      }
    }
  },
  mounted() {
    // this.$nextTick(this.init)
    setTimeout(this.init, 0)
  },
  computed: {
    fontSize() {
      return Math.floor(screen.height * 1.48 / 100)
    },
  },
  methods: {
    init() {
      this.chart = this.$echarts.init(this.$refs.chart)
      this.chart.setOption(this.option)
    }
  }
}
</script>

<style lang="stylus" scoped>
.disease-forecast
  width 100%
  height 100%
  >.chart
    width 100%
    height 95%
</style>
