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

<script>
import * as echarts from "echarts";
export default {
  props: ["datas"],
  watch: {
    datas: {
      handler(val) {
        this.hamdlegfChart();
      },
      immediate: true,
      deep: true,
    },
  },
  data() {
    return {
      echid: "",
    };
  },
  created() {
    this.echid = "ech_" + new Date().getTime();
  },
  mounted() {
    // this.titles = this.titles
    // this.datas = this.datas
    this.hamdlegfChart();
  },
  methods: {
    hamdlegfChart() {
      if (document.getElementById(this.echid)) {
        let myechart = echarts.init(document.getElementById(this.echid));
        myechart.setOption({
          tooltip: {},
          grid: {
            left: "5",
            right: "5",
            bottom: "0",
            top: "35",
            containLabel: true,
          },
          legend: {
            textStyle: {
              color: "#333",
            },
          },
          dataset: {
            // dimensions: ['product', '警情', '时长', '里程'],
            source: this.datas,
          },
          xAxis: {
            type: "category",
          },
          yAxis: {
            type: "value",
            splitLine: {
              show: true,
              lineStyle: {
                // color: "#224465",
              },
            },
          },
          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: "#b6325f",
                    },
                    {
                      offset: 1,
                      color: "#ff887c",
                    },
                  ],
                },
              ],
              barGap: "50%",
            },
            {
              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: "#205ddb",
                    },
                    {
                      offset: 1,
                      color: "#1bdffc",
                    },
                  ],
                },
              ],
            },
          ],
        });
      }
    },
  },
};
</script>

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