PieStatusChart.vue 1.93 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'

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: ["良品"],
         
        },
        series: [
          {
            name: "库存状态",
            type: "pie",
            radius: "55%",
            center: ["40%", "50%"],
            // data: data.seriesData,
            data: [
              {
                value: 2985,
                name: "良品",
              },
           
            ],
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)",
              },
            },
            animationEasing: "cubicInOut",
            animationDuration: 2600,
          },
        ],
      });
    }
  }
}
</script>