Blame view

src/views/dashboard/PieLocationChart.vue 2.06 KB
yuanshuhui authored
1
<template>
yuanshuhui authored
2
  <div :class="className" :style="{ height: height, width: width }" />
yuanshuhui authored
3
4
5
</template>

<script>
yuanshuhui authored
6
7
8
import echarts from "echarts";
require("echarts/theme/macarons"); // echarts theme
import resize from "./mixins/resize";
yuanshuhui authored
9
yuanshuhui authored
10
const animationDuration = 3000;
yuanshuhui authored
11
12
13
14
15
16

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
yuanshuhui authored
17
      default: "chart",
yuanshuhui authored
18
19
20
    },
    width: {
      type: String,
yuanshuhui authored
21
      default: "100%",
yuanshuhui authored
22
23
24
    },
    height: {
      type: String,
yuanshuhui authored
25
26
      default: "300px",
    },
27
28
    locationData: {
      type: Array,
yuanshuhui authored
29
30
      required: true,
    },
yuanshuhui authored
31
32
33
  },
  data() {
    return {
yuanshuhui authored
34
35
      chart: null,
    };
yuanshuhui authored
36
  },
yuanshuhui authored
37
  watch: {
38
39
    locationData: {
      handler(val) {
yuanshuhui authored
40
41
42
        this.setOptions(val);
      },
    },
43
  },
yuanshuhui authored
44
45
  mounted() {
    this.$nextTick(() => {
yuanshuhui authored
46
47
      this.initChart();
    });
yuanshuhui authored
48
49
50
  },
  beforeDestroy() {
    if (!this.chart) {
yuanshuhui authored
51
      return;
yuanshuhui authored
52
    }
yuanshuhui authored
53
54
    this.chart.dispose();
    this.chart = null;
yuanshuhui authored
55
56
57
  },
  methods: {
    initChart() {
yuanshuhui authored
58
      this.chart = echarts.init(this.$el, "macarons");
yuanshuhui authored
59
      this.setOptions(this.locationData);
60
    },
yuanshuhui authored
61
    setOptions(locationData) {
yuanshuhui authored
62
      this.chart.setOption({
yuanshuhui authored
63
64
65
        title: {
          text: "库位利用率",
          textStyle: {
yuanshuhui authored
66
67
68
69
            color: "rgba(0, 0, 0, 0.7)",
            fontSize: "15",
            fontWeight: "bold",
          },
yuanshuhui authored
70
        },
yuanshuhui authored
71
72
73
        tooltip: {
          trigger: "item",
          formatter: "{a} <br/>{b} : {c} ({d}%)",
yuanshuhui authored
74
        },
yuanshuhui authored
75
yuanshuhui authored
76
        legend: {
yuanshuhui authored
77
78
79
80
81
82
          type: "scroll",
          orient: "vertical",
          right: 10,
          top: 20,

          bottom: "20",
yuanshuhui authored
83
        },
yuanshuhui authored
84
85
86
87
88
89
        series: [
          {
            name: "货位状态",
            type: "pie",
            radius: "55%",
            center: ["40%", "50%"],
90
            data: locationData,
yuanshuhui authored
91
92
93
94
95
96
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)",
              },
yuanshuhui authored
97
            },
yuanshuhui authored
98
99
100
101
102
103
            animationEasing: "cubicInOut",
            animationDuration: 2600,
          },
        ],
      });
    },
yuanshuhui authored
104
  },
yuanshuhui authored
105
};
yuanshuhui authored
106
</script>