<template>
  <div :id="echid" class="gfChart"></div>
</template>

<script>
import * as echarts from "echarts";
export default {
  props: ["list"],
  watch: {
    list: {
      handler(val) {
        this.hamdlegfChart();
      },
      immediate: true,
      deep: true,
    },
  },
  data() {
    return {
      echid: "",
      themeType: getStorage("themeSetting"),
    };
  },
  created() {
    this.echid = "echi_et" + new Date().getTime();
  },
  mounted() {
    this.hamdlegfChart();
  },
  methods: {
    hamdlegfChart() {
      if (document.getElementById(this.echid)) {
        let myChart = echarts.init(document.getElementById(this.echid));
        var option = {
          grid: {
            left: "0",
            right: "0",
            bottom: "48",
            top: "10",
            containLabel: true,
          },
          legend: {
            left: "center",
            bottom: 0, //具体
            textStyle: {
              color: this.themeType == "light" ? "#333" : "#fff",
            },
          },
          tooltip: {},
          dataset: {
            source: this.list,
          },
          xAxis: {
            type: "category",
            axisLabel: {
              color: this.themeType == "light" ? "#333" : "#fff",
            },
          },
          yAxis: {
            splitLine: { show: false },
            axisLabel: {
              color: this.themeType == "light" ? "#333" : "#fff",
            },
          },
          series: [
            {
              type: "bar",
              barWidth: 9,
              itemStyle: {
                normal: {
                  // barBorderRadius: [5, 5, 5, 5],
                },
              },
              color: [
                {
                  type: "linear",
                  x: 0,
                  y: 0,
                  x2: 0,
                  y2: 1,

                  colorStops: [
                    {
                      offset: 0,
                      color: "#1eabff",
                    },
                    {
                      offset: 1,
                      color: "#4760ff",
                    },
                  ],
                },
              ],
            },
            {
              type: "bar",
              barWidth: 9,
              itemStyle: {
                normal: {
                  // barBorderRadius: [5, 5, 5, 5],
                },
              },
              color: [
                {
                  type: "linear",
                  x: 0,
                  y: 0,
                  x2: 0,
                  y2: 1,
                  colorStops: [
                    {
                      offset: 0,
                      color: "#88f2b9",
                    },
                    {
                      offset: 1,
                      color: "#0dda72",
                    },
                  ],
                },
              ],
            },
            {
              type: "bar",
              barWidth: 9,
              itemStyle: {
                normal: {
                  // barBorderRadius: [5, 5, 5, 5],
                },
              },
              color: [
                {
                  type: "linear",
                  x: 0,
                  y: 0,
                  x2: 0,
                  y2: 1,
                  colorStops: [
                    {
                      offset: 0,
                      color: "#ffd91b",
                    },
                    {
                      offset: 1,
                      color: "#ff8e43",
                    },
                  ],
                },
              ],
            },
            {
              type: "bar",
              barWidth: 9,
              itemStyle: {
                normal: {
                  // barBorderRadius: [5, 5, 5, 5],
                },
              },
              color: [
                {
                  type: "linear",
                  x: 0,
                  y: 0,
                  x2: 0,
                  y2: 1,
                  colorStops: [
                    {
                      offset: 0,
                      color: "#f87373",
                    },
                    {
                      offset: 1,
                      color: "#e81b1b",
                    },
                  ],
                },
              ],
            },
            {
              type: "bar",
              barWidth: 9,
              itemStyle: {
                normal: {
                  // barBorderRadius: [5, 5, 5, 5],
                },
              },
              color: [
                {
                  type: "linear",
                  x: 0,
                  y: 0,
                  x2: 0,
                  y2: 1,
                  colorStops: [
                    {
                      offset: 0,
                      color: "#f9906f",
                    },
                    {
                      offset: 1,
                      color: "#f05654",
                    },
                  ],
                },
              ],
            },
          ],
        };
        option && myChart.setOption(option);
      }
    },
  },
};
</script>

<style scoped>
.gfChart {
  margin-top: 1vw;
  height: 100%;
  width: 100%;
  margin: 0 auto;
}
</style>
