ex1.vue 3.75 KB
<template>
  <div>
    <div class="pie">
      <div id="pie1">
        <!-- 为 ECharts 准备一个具备大小(宽高)的 DOM -->
        <div id="main1" style="width: 100%; height: 260px"></div>
      </div>
    </div>
  </div>
</template>
  
  <script>
// 引入基本模板
let echarts = require("echarts/lib/echarts");
// 引入饼状图组件
require("echarts/lib/chart/pie");
// 引入提示框和title组件
require("echarts/lib/component/tooltip");
require("echarts/lib/component/title");

export default {
  created() {},
  mounted() {
    //   this.initData();
  },
  methods: {
    //初始化数据
    initData(x, y) {
      // 基于准备好的dom,初始化echarts实例
      var myChart = echarts.init(document.getElementById("main1"));
      // 绘制图表
      myChart.setOption({
        title: {
          text: "今日进件量分析",
          subtext: "",
          left: "center",
        },
        tooltip: {
          trigger: "item",
          formatter: "{a} <br/>{b} : {c} ({d}%)",
        },
        legend: {
          orient: "vertical",
          left: "left",
        },
        series: [
          {
            name: "今日进件数据分析",
            type: "pie",
            radius: "70%",
            avoidLabelOverlap: true,
            // roseType: "angle",
            // label: {
            //   normal: {
            //     show: false,
            //   },
            // },
            // labelLine: {
            //   normal: {
            //     show: false,
            //   },
            // },
            data: [
              {
                value: y[0],
                name: x[0],
                itemStyle: {
                  normal: {
                    label: {
                      show: true,
                      formatter: function (params, option) {
                        if (params.data.value == 0) {
                          params.data.label.normal.show = false;
                          params.data.labelLine.normal.show = false;
                        }
                      },
                    },
                    labelLine: {
                      show: true,
                    },
                  },
                },
              },
              {
                value: y[1],
                name: x[1],
                itemStyle: {
                  normal: {
                    label: {
                      show: true,
                      formatter: function (params, option) {
                        if (params.data.value == 0) {
                          params.data.label.normal.show = false;
                          params.data.labelLine.normal.show = false;
                        }
                      },
                    },
                    labelLine: {
                      show: true,
                    },
                  },
                },
              },
              {
                value: y[2],
                name: x[2],
                itemStyle: {
                  normal: {
                    label: {
                      show: true,
                      formatter: function (params, option) {
                        if (params.data.value == 0) {
                          params.data.label.normal.show = false;
                          params.data.labelLine.normal.show = false;
                        }
                      },
                    },
                    labelLine: {
                      show: true,
                    },
                  },
                },
              },
            ],
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)",
              },
            },
          },
        ],
      });
    },
  },
};
</script>