<template>
<!-- 档案利用 -->
  <div :class="className" :style="{height:height,width:width}" />
</template>
<script>
import echarts from "echarts";
require("echarts/theme/macarons"); // echarts theme
import resize from "./mixins/resize";
// import { baoguanqixian } from "@/api/dashboard";

const animationDuration = 3800;
export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: "chart",
    },
    width: {
      type: String,
      default: "100%",
    },
    height: {
      type: String,
      default: "100%",
      // default: (window.innerHeight-260)/2+"px"
    },
    autoResize: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {
      chart: null,
      chartOption:{
        tooltip: {
          trigger: 'axis',
        },
        xAxis: {
          type: 'category',
          data: ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'],
          axisLine: {
            show: false, //不显示坐标轴轴线
            lineStyle: {
              color: "#a0a0a0",
            },
          },
          axisLabel: {
            interval: 0, // 坐标轴刻度标签的显示间隔

            // rotate: 40 // 标签倾斜的角度
            textStyle: {
              fontSize: 10, //刻度大小
              color: "#a0a0a0",
            },
          },
        },
        grid: {
          top: "5%",
          left: "0%",
          right: "0%",
          bottom: "0%",
          containLabel: true,
        },
        yAxis: {
          type: 'value',
          splitLine: {
            show: false, // 不显示网格线
          },
          axisTick: {
            show: false,
          },
          axisLine: {
            show: false, //不显示坐标轴轴线
            lineStyle: {
              color: "#a0a0a0",
            },
          },
          axisLabel: {
            textStyle: {
              fontSize: 10, //刻度大小
              color: "#a0a0a0",
            },
            rotate: 30
          },
        },
        series: [
          {
            data: [0,0,300,200,20,0,300,60,20,28,35,50],
            type: 'line',
            itemStyle:{
              normal:{
                color: '#6dd1a8'
              }
            },
             areaStyle: {
              opacity: 0.6,
              color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [
                {
                  offset: 0,
                  color: 'rgb(80, 197, 211)'
                },
                {
                  offset: 1,
                  color: 'rgb(112, 207, 163)'
                }
              ])
            },
          }
        ]
      }
    };
  },
  methods: {
    fileUse() {
        this.chart.setOption(this.chartOption);
        
    },
    initChart() {
      this.chart = echarts.init(this.$el, "macarons");
      this.fileUse();
    },
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart();
    });
  },
  beforeDestroy() {
    if (!this.chart) {
      return;
    }
    this.chart.dispose();
    this.chart = null;
  },
};
</script>
