PieInventoryChart.vue 3.23 KB
<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'

const animationDuration = 6000

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '300px'
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')
     this.chart.setOption({
        title: {
          text: "库存概况",
          textStyle: {
          color: 'rgba(0, 0, 0, 0.7)',
          fontSize: '15',
          fontWeight:'bold'
        }
        },
        tooltip: {
          trigger: "item",
          formatter: "{a} <br/>{b} : {c} ({d}%)",
        },

        legend: {
          type: "scroll",
          orient: "vertical",
          right: 10,
          top: 20,

          bottom: "20",
          data: ["音箱", "不锈钢挂钩","电话机", "来访证","警犬狗链", "会议电话,MEETEASY ME","烟灰缸,180*180", "绘图纸,A0/880MM*50M/80G","双耳环,SG-M16*1.5", "气缸,DSBC-50-50-PPSA-N3"],
          selected: {
            "烟灰缸,180*180":false, "绘图纸,A0/880MM*50M/80G":false,"双耳环,SG-M16*1.5":false, "气缸,DSBC-50-50-PPSA-N3":false
          }
        },
        series: [
          {
            name: "库存",
            type: "pie",
            radius: "55%",
            center: ["40%", "50%"],
            // data: data.seriesData,
            data: [
              {
                value: 1513,
                name: "音箱",
              },
              {
                value: 631,
                name: "不锈钢挂钩",
              },
               {
                value: 280,
                name: "电话机",
              },
              {
                value: 116,
                name: "来访证",
              },
               {
                value: 100,
                name: "警犬狗链",
              },
              {
                value: 100,
                name: "会议电话,MEETEASY ME",
              },
               {
                value: 100,
                name: "烟灰缸,180*180",
              },
              {
                value: 90,
                name: "绘图纸,A0/880MM*50M/80G",
              },
               {
                value: 50,
                name: "双耳环,SG-M16*1.5",
              },
              {
                value: 5,
                name: "气缸,DSBC-50-50-PPSA-N3",
              },
            ],
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)",
              },
            },
            animationEasing: "cubicInOut",
            animationDuration: 2600,
          },
        ],
      });
      
    }
  }
}
</script>