<template>
  <div class="countryLineChart" ref="countryLineChart"></div>
</template>

<script>
// import * as echarts from "echarts";
// import config from "@/config/index";
import * as echarts from "echarts/core";
import { GaugeChart } from "echarts/charts";
import { TooltipComponent } from "echarts/components";
import { CanvasRenderer } from "echarts/renderers";
echarts.use([CanvasRenderer, TooltipComponent, GaugeChart]);
let pieTypeOneCharts = undefined;
export default {
  name: "countryLineChart",
  props: ["list"],
  data: function() {
    return {
      leftList: [],
      rightList: [],
      chart: undefined,
    };
  },
  filters: {},
  watch: {
    list() {
      pieTypeOneCharts && pieTypeOneCharts.dispose();
      this.createChart();
    },
  },
  methods: {
    createChart() {
      if (!this.$refs.countryLineChart) return;
      if (!pieTypeOneCharts) {
        pieTypeOneCharts = echarts.init(this.$refs.countryLineChart);
        pieTypeOneCharts.resize({
          height: (this.$refs.countryLineChart.offsetWidth * 6) / 16,
        });
      }
      var option = {
        series: this.list.map((v, i) => {
          let y = i < 5 ? 25 : 75;
          return {
            color: "#00bed0",
            type: "gauge",
            startAngle: 90,
            endAngle: -270,
            center: [((10 + i * 20) % 100) + "%", y + "%"],
            pointer: {
              show: false,
            },
            progress: {
              show: true,
              overlap: false,
              roundCap: true,
              clip: false,
              itemStyle: {
                borderWidth: 0,
              },
            },
            axisLine: {
              lineStyle: {
                width: 10,
              },
            },
            splitLine: {
              show: false,
              distance: 0,
              length: 5,
            },
            axisTick: {
              show: false,
            },
            axisLabel: {
              show: false,
              distance: 50,
            },
            radius: "40%",
            data: [
              {
                value: (v.score * 100).toFixed(2) - 0,
                name: v.name,
                title: {
                  offsetCenter: ["0%", "-15%"],
                  width: 100,
                  overflow: "truncate",
                },
                detail: {
                  valueAnimation: true,
                  offsetCenter: ["0%", "15%"],
                },
              },
            ],
            title: {
              fontSize: 14,
            },
            detail: {
              width: 20,
              height: 14,
              fontSize: 14,
              color: "inherit",
              borderWidth: 0,
              formatter: "{value}%",
            },
          };
        }),
      };

      option && pieTypeOneCharts.setOption(option);
    },
  },
  mounted() {
    pieTypeOneCharts && pieTypeOneCharts.dispose();
    this.createChart();
  },
  beforeUnmount: function() {
    pieTypeOneCharts && pieTypeOneCharts.dispose();
  },
  components: {},
};
</script>
<style></style>
