<template>
  <div id="main" :style="{ height: height, width: width }" />
</template>

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

export default {
  props: {
    width: {
      type: String,
      default: "100%"
    },
    height: {
      type: String,
      default: "330px"
    }
  },
  data() {
    return {};
  },
  mounted() {
    this.initChart();
  },
  methods: {
    initChart() {
      var myChart = echarts.init(document.getElementById("main"));
      // 绘制图表
      myChart.setOption({
        // title: {
        //   text: "Stacked Line"
        // },
        tooltip: {
          trigger: "axis"
        },
        legend: {
          bottom: "0%",
          data: [
            "集团",
            "太原市人民医院",
            "永乐苑社区卫生院",
            "八一社区卫生院",
            "安澜社区卫生院",
            "沙井社区卫生院"
          ]
        },
        color: [
          "#1847F5",
          "#E99D42",
          "#58A55C",
          "#F2BD42",
          "#EE752F",
          "#D95040"
        ],
        grid: {
          top: "5%",
          left: "3%",
          right: "4%",
          bottom: "15%",
          containLabel: true
        },
        toolbox: {
          feature: {
            // saveAsImage: {}
          }
        },
        xAxis: {
          type: "category",
          boundaryGap: false,
          data: [
            "1月",
            "2月",
            "3月",
            "4月",
            "5月",
            "6月",
            "7月",
            "8月",
            "9月",
            "10月",
            "11月",
            "12月"
          ]
        },
        yAxis: {
          type: "value"
        },
        series: [
          {
            name: "集团",
            type: "line",
            data: [
              1001, 1401, 1301, 1192, 1640, 1625, 1345, 1291, 1134, 1267, 1123,
              1234
            ],
            // areaStyle: {},
            smooth: true
          },
          {
            name: "太原市人民医院",
            type: "line",
            data: [220, 182, 191, 234, 290, 330, 310, 220, 182, 191, 234, 290],
            smooth: true
          },
          {
            name: "永乐苑社区卫生院",
            type: "line",
            data: [150, 232, 201, 154, 190, 330, 410, 150, 232, 201, 154, 190],
            smooth: true
          },
          {
            name: "八一社区卫生院",
            type: "line",
            data: [320, 332, 301, 334, 390, 330, 320, 320, 332, 301, 334, 390],
            smooth: true
          },
          {
            name: "安澜社区卫生院",
            type: "line",
            data: [220, 332, 201, 334, 290, 230, 130, 220, 332, 201, 334, 290],
            smooth: true
          },
          {
            name: "沙井社区卫生院",
            type: "line",
            data: [220, 232, 401, 234, 490, 230, 420, 220, 232, 401, 234, 490],
            smooth: true
          }
        ]
      });

      window.addEventListener("resize", () => {
        if (myChart) {
          myChart.resize();
        }
      });
    }
  }
};
</script>
