<template>
  <div class="chart-container">
    <div ref="chart" class="chart-body" />
  </div>
</template>

<script>
import echarts from 'echarts'
export default {
  name: 'HighFreqChart4Sup',
  props: {
    list: {
      type: Array,
      default() {
        return []
      }
    }
  },
  computed: {
    pieData() {
      const tmp = []
      this.list.forEach((item, index) => {
        const obj = {}
        obj.name = item.caseMajorType
        obj.value = item.caseNum
        tmp.push(obj)
      })
      return tmp
    }
  },
  watch: {
    list() {
      this.initChart()
    }
  },
  activated() {
    this.initChart()
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$refs.chart)
      this.chart.setOption({
        // backgroundColor: '#ccc',
        tooltip: {
          show: true
        },
        grid: {
          bottom: 120
        },
        legend: {
          type: 'scroll',
          bottom: 0,
          textStyle: {
            color: '#333333'
          },
          pageTextStyle: {
            color: '#333333'
          },
          pageIconColor: '#333333'
        },
        toolbox: {
          show: true,
          right: '20',
          feature: {
            dataView: {
              show: false
            }
          }
        },
        color: [
          '#19d4ae', '#5ab1ef', '#fa6e86',
          '#ffb980', '#0067a6', '#c4b4e4',
          '#d87a80', '#9cbbff', '#d9d0c7',
          '#87a997', '#d49ea2', '#5b4947',
          '#7ba3a8'
        ],
        series: [{
          name: '高发问题',
          type: 'pie',
          data: this.pieData,
          label: {
            show: false
          },
          tooltip: {
            formatter: '{b}<br/>上报数: {c} ({d}%)'
          }
        }]
      })
      this.chart.resize()
    }
  }
}
</script>

<style scoped>
.chart-container {
  /*text-align: center;*/
}
.chart-body {
  /*height: 60vh;*/
  min-height: 240px;
  width: 90%;
  margin-right: auto;
  margin-left: auto;
}
</style>
