<template>
  <div>
    <div id="productProportion" style="width:5.25rem; height: 2.75rem;"></div>
  </div>
</template>

<script>
import resize from "./mixins/resize";

export default {
  data() {
    return {
      chart: null
    };
  },
  mixins: [resize],
  mounted() {
    this.initChart();
  },
  methods: {
    initChart() {
      // 基于准备好的dom，初始化echarts实例
      this.chart = this.echarts.init(document.getElementById("productProportion"));

      this.chart.setOption({
        color: [
          "#37a2da",
          "#32c5e9",
          "#9fe6b8",
          "#ffdb5c",
          "#ff9f7f",
          "#fb7293",
          "#e7bcf3",
          "#8378ea"
        ],
        tooltip: {
          trigger: "item",
          formatter: "{b} : {c} ({d}%)"
        },
        toolbox: {
          show: true
        },
        calculable: true,
        legend: [{
          icon: "circle",
          orient: 'vertical',
          right: 75,
          top: 40,
          bottom: 20,
          data: ["H2", "C2H4", "CH4", "C3H6"],
          textStyle: {
            color: "#fff"
          }
        }, {
          icon: "circle",
          orient: 'vertical',
          right: 5,
          top: 40,
          bottom: 20,
          data: ["Offags", "LPG", "C4", "RPG"],
          textStyle: {
            color: "#fff"
          }
        }],
        label: {
          alignTo: 'edge',
          formatter: '{name|{b}}\n{weight|{c} 吨({d}%)}',
          minMargin: 5,
          edgeDistance: 10,
          lineHeight: 15,
          rich: {
            name: {
              fontSize: 12,
              color: '#ffffff'
            },
            weight: {
              fontSize: 8,
              color: '#999'
            }
          }
        },
        series: [
          {
            type: "pie",
            radius: [10, 55],
            roseType: "area",
            center: ["36%", "40%"],
            data: [
              { value: 1550, name: "H2" },
              { value: 555, name: "C2H4" },
              { value: 1555, name: "CH4" },
              { value: 2555, name: "C3H6" },
              { value: 250, name: "Offags" },
              { value: 3555, name: "LPG" },
              { value: 350, name: "C4" },
              { value: 4555, name: "RPG" }
            ],
          }
        ]
      });
    }
  },
  destroyed() {
    window.onresize = null;
  }
};
</script>

<style lang="scss" scoped>
</style>
