vue中el-card结合echarts中的柱形图,一起获取数据

echarts中的柱形图与vue中的卡片区一起结合,获取柱形图的数据

<template>
  <div class="all">
    <el-card shadow="hover">
      <div id="topRight" style="height:400px"></div>
    </el-card>
  </div>
</template>
<script>
import { prjInfo, userInfo } from "@/mixins/index";
import { CHART_COLORS } from "@/commons";
import echarts from "echarts/lib/echarts";
import "echarts/lib/chart/line";
import "echarts/lib/component/title";
import "echarts/lib/component/legend";
export default {
  mixins: [prjInfo],
  data() {
    return {
      type: 0
    };
  },
  mounted() {
    this.getEcharts();
  },
  methods: {
    getEcharts() {
      //柱形图
      const params = {
        type: 0,
        pID: this.prjId
      };
      getPassRateDivisional(params).then(({ data }) => {
        var myChartRight = echarts.init(document.getElementById("topRight"));
        var option2 = {
          color: CHART_COLORS,
          title: {
            text: "分布工程合格率",
            top: "30",
            left: "center"
          },
          legend: {
            right: 10
          },
          tooltip: {},
          xAxis: {
            type: "category",
            axisLabel: {
              interval: 0, //横轴信息全部显示
              rotate: -15 //-15度角倾斜显示
            },
            data: data.map(item => item.prjDivisionalName)
          },
          yAxis: {
            name: "%"
          },
          series: [
            {
              name: "合格率",
              type: "bar",
              barWidth: 10,
              data: data.map(item => item.passRate)
            },
            {
              name: "区域合格率",
              type: "bar",
              barWidth: 10,
              data: data.map(item => item.deptPassRate)
            }
          ]
        };
        myChartRight.setOption(option2);
      });
    }
  }
};
</script>

效果图如下所示:

vue中el-card结合echarts中的柱形图,一起获取数据_第1张图片

你可能感兴趣的:(vue中el-card结合echarts中的柱形图,一起获取数据)