ex3.vue 2.1 KB
<template>
  <div>
    <div class="pie">
      <div id="pie2">
        <!-- 为 ECharts 准备一个具备大小(宽高)的 DOM -->
        <div id="main2" 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 {
  data() {
    return {
      zhuX: [],
      zhuY: [],
    };
  },
  created() {},
  mounted() {
    //   this.initData();
  },
  methods: {
    //初始化数据
    initData(x, y) {
      // 基于准备好的dom,初始化echarts实例
      var myChart = echarts.init(document.getElementById("main2"));
      // 绘制图表
      myChart.setOption({
        title: {
          text: "决策节点通过率分析",
          subtext: "",
          left: "center",
        },
        color: ["#409EFF"],
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow",
          },
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          y2: 150,
          containLabel: true,
        },
        xAxis: [
          {
            type: "category",
            data: x,
            axisTick: {
              alignWithLabel: true,
            },
            axisLabel: {
              interval:0,
              rotate:-25
            },
          },
        ],
        yAxis: [
          {
            type: "value",
          },
        ],
        series: [
          {
            name: "处理总量",
            type: "bar",
            barWidth: "60%",
            label: {
              // 柱图头部显示值
              show: true,
              position: "top",
              color: "#333",
              fontSize: "12px",
              formatter: (params) => {
                return params.value[params.encode.x[0]];
              },
            },
            data: y,
          },
        ],
      });
    },
  },
};
</script>