<!--  -->
<template>
  <div :id="id" />
</template>

<script>
export default {
  // eslint-disable-next-line
  props: {
    id: {
      type: String,
      default: "",
    },
    data: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    // 这里存放数据
    return {
      mapChart: null,
    };
  },

  computed: {},

  watch: {
    data: {
      handler(newVal, oldVal) {
        this.drawGraph(this.id, newVal);
      },
      deep: true,
    },
  },

  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
    this.drawGraph(this.id, this.data);
  },
  // 方法集合
  methods: {
    drawGraph(id, data) {
      const self = this;
      const myChart = document.getElementById(id);
      self.mapChart = self.$echarts.init(myChart);
      const options = {
        tooltip: {
          // 鼠标悬停提示内容
          trigger: "axis", // 触发类型，默认数据触发，可选为：'axis' item
          axisPointer: {
            // 坐标轴指示器，坐标轴触发有效
            type: "line", // 默认为直线，可选为：'line' | 'shadow'
            label: "cross",
            show: true,
          },
        },
        grid: {
          left: "17%",
          right: "1%",
          y: "7%", // y 偏移量
          width: "auto", // 宽度
          height: "69%", // 高度,
        },
        xAxis: {
          type: "category",
          boundaryGap: false,
          data: xData,
          axisTick: {
            show: false,
          },
          axisLine: {
            lineStyle: {
              color: "#206AA9",
            },
          },
          axisLabel: {
            interval: self.axisLabelInterval, // 坐标刻度之间的显示间隔，默认就可以了（默认是不重叠）
            rotate: 38, // 调整数值改变倾斜的幅度（范围-90到90）
            textStyle: {
              color: "#AAC5E1", // 坐标的字体颜色
              fontSize: 10,
            },
          },
        },
        yAxis: {
          type: "value",
          // max: 2000,
          // interval: 500,
          // minInterval: 500,
          axisTick: {
            show: false,
          },
          axisLine: {
            lineStyle: {
              color: "#206AA9",
            },
          },
          splitLine: {
            lineStyle: {
              color: "#206AA9",
              type: "dashed",
            },
          },
          axisLabel: {
            textStyle: {
              color: "#AAC5E1", // 坐标的字体颜色
              fontSize: 10,
            },
          },
        },
        series: [
          {
            data: yData,
            type: "line",
            smooth: true,
            areaStyle: {
              normal: {
                color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
                  {
                    offset: 0,
                    color: "rgba(82, 253, 247, 1)",
                  },
                  {
                    offset: 1,
                    color: "rgba(138, 255, 252, 0)",
                  },
                ]),
              },
            },
            itemStyle: {
              normal: {
                color: "#52FDF7", // 改变折线点的颜色
                lineStyle: {
                  color: "#52FDF7", // 改变折线颜色
                },
              },
            },
          },
        ],
      };
      self.lineChartGraph.setOption(options);
      window.addEventListener("resize", () => {
        self.lineChartGraph.resize();
      });
    },
  }, // 如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style lang='scss' scoped>
//@import url(); 引入公共css类
</style>
