<template>

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

<script>
import * as echarts from 'echarts';

export default {
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '350px'
    },
    autoResize: {
      type: Boolean,
      default: true
    },
    chartData: {
      type: Object,
      default:{}
    }
  },
  data() {
    return {
      chart: null
    }
  },
  watch: {
    chartData: {
      deep: true,
      handler(val) {
        this.setOptions(val)
      }
    }
  },
  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.setOptions(this.chartData)
    },
    setOptions() {
      this.chart.setOption({
        // backgroundColor: "#041139",
        color: "#04CFE4",
        grid: {
          top: 80,
          left: 60,
          right: 40,
          bottom: 60
        },
        xAxis: {
          type: 'category',
          axisTick: false,
          axisLabel: {
            interval: 0,
            color: '#fff',
            fontSize: 14
          },
          data: ['2025', '2026', '2027', '2028', '2029', '2030', '2031', '2032', '2033', '2034']
        },
        yAxis: {
          type: 'value',
          interval: 100,
          splitLine: false,
          axisLabel: {
            color: '#fff'
          }
        }, title: {
          text: '达到预估寿命极限的管道统计', // 标题内容  // 水平居中
          top: '7%',
          left: '3%',   // 距离顶部5%
          textStyle: {     // 文字样式
            color: '#fff',
            fontSize: 16,
            fontWeight: 'normal'
          }
        },
        series: [
          {
            data: [10, 20, 15, 52, 55, 54, 67, 76, 332, 73],
            type: "pictorialBar",
            symbol: "path://M0,10 L10,10 C5.5,10 5.5,5 5,0 C4.5,5 4.5,10 0,10 z",
            label: {
              show: true,
              color: '#fff',
              position: 'top'
            }
          }
        ]
      })
    }
  }
}
</script>
