<template>
  <div>
    <div id="centreRight2Chart2" style="width:3.25rem; height: 3.7rem;"></div>
  </div>
</template>

<script>
import echartMixins from "@/utils/resizeMixins";

export default {
  data() {
    return {
      chart: null
    };
  },
  mixins: [echartMixins],
  mounted() {
    this.draw();
  },
  methods: {
    draw() {
      // 基于准备好的dom，初始化echarts实例
      this.chart = this.$echarts.init(document.getElementById("centreRight2Chart2"));
      //  ----------------------------------------------------------------
      let lineStyle = {
        normal: {
          width: 1,
          opacity: 0.5
        }
      };

      let option = {
        color: ['#62DBE8'],
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          }
        },
        legend: {
          padding: [5, 10, 0, 10],
          itemGap: 50,
          textStyle: { //图例文字的样式
            color: '#fff',
            fontSize: 8
          }
        },
        grid: {
          top: '6%',
          left: '4%',
          right: '16%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: {
          show: false // 不显示横坐标
        },
        yAxis: {
          type: 'category',
          data: ['Brazil', 'Indonesia', 'USA', 'India', 'China', 'World'],
          offset: 15,
          boundaryGap: ['20%', '20%'],
          axisLabel: {
            show: true,
            textStyle: {
              color: '#fff',
              fontSize: '10',
              fontWeight: 'bold'
            }
          }
        },
        series: [
          {
            type: 'bar',
            data: [19325, 23438, 31000, 121594, 134141, 68180],
            barWidth: 16, //柱子宽度
            barGap: 0, //柱子之间间距
            itemStyle: {
              normal: {
                label: {
                  formatter: "{c}"+"件",
                  show: true,
                  position: [140, 0],
                  textStyle: {
                    fontWeight: "bold",
                    fontSize: "10",
                    color: "#fff"
                  }
                },
                opacity: 1
              }
            }
          }
        ]   
      };
      this.chart.setOption(option);
    }
  },
  destroyed() {
    window.onresize = null;
  }
};
</script>

<style lang="scss" scoped>
#centreRight2Chart2 {
  margin: 0 auto;
}
</style>