<template>
  <div>
    <div class="label">异常情况汇报</div>
    <div id="excep" class="d1"></div>
  </div>
</template>

<script>
  export default {
    name: "sale-proportion",
    data() {
      return {
        xc: '',
        visible: false,
        content: '',
        duration: 3000
      }
    },
    methods: {
      setBar() {
        this.xc = this.$echarts.init(document.getElementById('excep'))
        var scale = 0.8
        var xAxisData = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '', ''];
        var legendData = ['故障', '报警'];
        var colors1 = ["#0b272f", "#0b272f"];
        var colors2 = ["#2f4038", "#2e4d48"];
        var colors3 =  ['#f7cb32', "#6fd9d0"];
        var serieData = [];
        var metaDate = [
          [12.6, 25.9, 9.0, 62.4, 28.7, 70.7, 45.6, 82.2, 48.7, 18.8, 26.0, 22.3],
          [13.9, 15.9, 11.1, 18.27, 48.3, 69.2, 31.6, 46.6, 55.4, 28.4, 20.23, 10.7]
        ]
        for (var v = 0; v < legendData.length; v++) {
          var serie = {
            name: legendData[v],
            type: 'line',
            smooth: false  ,  // true: 光滑曲线  , false: 直线
            symbol: 'circle',
            symbolSize: 5 * scale,
            areaStyle: {
              normal: {
                color: new this.$echarts.graphic.LinearGradient(
                  0, 0, 0, 1,
                  [
                    {offset: 0, color: colors1[v]},
                    {offset: 0.5, color: colors2[v]},
                    {offset: 1, color: colors3[v]}
                  ]
                )
              }
            },
            itemStyle: {
              normal: {
                lineStyle: {
                  width: 1,
                }
              }
            },
            data: metaDate[v]
          }
          serieData.push(serie)
        }
        this.xc.setOption({
          title: {
            text: "",
            textAlign: 'left',
            textStyle: {color: "#FFFFFF", fontSize: 12 * scale, fontWeight: "normal"}
          },
          legend: {
            itemGap: 0,
            width: '90%',
            show: true,
            left: "right",
            data: legendData,
            y: 'top',
            itemWidth: 12 * scale,
            itemHeight: 6 * scale,
            textStyle: {width: '20%', color: "#15dce2", fontSize: 14 * scale},
            formatter: function (params) {
              return params
            },
          },
          grid: {left: '5%', top: "18%", bottom: "5%", right: "5%",containLabel: true},
          color: ['#f7cb32', "#6fd9d0"],
          tooltip: {
            formatter: function (params) {
              if (params[0].data == '') {
                return ''
              }
              var result = ''
              params.forEach(function (item) {
                result += item.marker + " " + item.seriesName + " : " + item.value + "</br>";
              });
              return params[0].axisValue + '<br/><br/>' + result
            },
            trigger: 'axis',
            extraCssText: 'width: auto;height: auto;',
            axisPointer: {type : 'line',lineStyle: {width: 0}},
          },
          xAxis: [{
            name: '      月份\n(2018-2019)',
            type: 'category',
            nameTextStyle: {
              fontSize: 12 * scale,
              color: '#15dce2',
              padding: [38, 0, 0, -75 * scale],
            },
            axisLine: {show: true, lineStyle: {color: '#04669e', width: 1}},
            axisLabel: {interval: 0, textStyle: {color: '#ffffff', fontSize: 14 * scale}},
            axisTick: {show: false},
            data: xAxisData
          }],
          yAxis: [{
            name: '次数',
            nameTextStyle: {
              fontSize: 12 * scale,
              padding: [0, 35 * scale, 0, 0],
            },
            axisTick: {show: false},
            splitLine: {show: true, lineStyle: {type: 'dashed', color: '#004371'}},
            axisLabel: {textStyle: {color: '#15dce2', fontSize: 14 * scale}, formatter: function (params) {
                return params
              }},
            axisLine: {show: false, lineStyle: {color: '#15dce2', fontSize: 14 * scale}},
          }],
          series: serieData
        })
      },
    },

    ready() {
      this.setBar()
    }
  }
</script>

<style scoped>
  .label {
    margin-left: 6%;
    font-size: 0.85em;
    color: #fff;
    width: 100%;
    height: 9%;
  }

  #excep {
    height: 91%;
    width: 99%;
    padding: 1% 2% 3% 2%;

  }
</style>
