vue:echarts引入以及获取动态数据

参考链接:echarts引入
动态获取数据:

<template>
  <el-card class="box-card">
    <h1 align="center">人事管理系统</h1>
    <div id="zhu" style="width: 100%;height: 400px;"></div>
    <div id="bin" style="width: 100%;height: 400px;"></div>
  </el-card>
</template>

<script>
  export default {
    data() {
      return {}
    },
    methods: {
      /**
       * 获取员工数据
       */
      getAllEmployee() {
        this.$axios({
          method: 'post',
          headers: {
            'Content-Type': 'application/json'
          },
          url: 'http://127.0.0.1:8080/employee/getAllEmployee',
          data: {

          }
        }).then((response) => {
          if (response.data.msg != "SUCCESS") {
            this.$message.error(response.data.msg);
          }
          //数据封装
          var data = [
            response.data.data.records[0].rs,
            response.data.data.records[0].cw,
            response.data.data.records[0].xz,
            response.data.data.records[0].sc
          ]

          this.getZhu(data);
        }).catch((error) => {
          console.log(error)
        })
      },
      //柱状图
      getZhu: function (data) {
        let myEchart = this.$echarts.init(document.getElementById("zhu"));
        myEchart.setOption({
          xAxis: {  //x轴
            //  数据条目名称
            data: ['人事', '财务', '行政', '市场']
          },
          yAxis: {}, //y轴
          series: [
            {
              type: 'bar',    //图表类别: bar :柱状图
              //  值
              data: data
            }
          ]
        })
      },
      /**
       * 获取出勤数据
       */
      getAttendanceTableDate() {
        this.$axios({
          method: 'post',
          headers: {
            'Content-Type': 'application/json'
          },
          url: 'http://127.0.0.1:8080/employeeAttendance/getAntt',
          data: {
          }
        }).then((response) => {
          if (response.data.msg != "SUCCESS") {
            this.$message.error(response.data.msg);
          }
          //数据封装
          var data = [
            {value: response.data.data.records[0].zc, name: '正常'},
            {value: response.data.data.records[0].cd, name: '迟到'},
            {value: response.data.data.records[0].zt, name: '早退'},
            {value: response.data.data.records[0].qq, name: '缺勤'},
            {value: response.data.data.records[0].qj, name: '请假'}
          ]
          this.getBin(data);
        }).catch((error) => {
          console.log(error)
        })
      },
      getBin: function (data) {
        let myEchart = this.$echarts.init(document.getElementById("bin"));
        myEchart.setOption({
          tooltip: {
            trigger: 'item'
          },
          legend: {
            orient: 'vertical',
            left: 'left'
          },
          series: [
            {
              name: '员工考勤',
              type: 'pie',
              radius: '50%',
              data: data,
              emphasis: {
                itemStyle: {
                  shadowBlur: 10,
                  shadowOffsetX: 0,
                  shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
              }
            }
          ]
        });
      },
    },
    //  *注意不要写在creatd()里  会出现dom元素未加载报错
    //  推荐写在mounted()里
    mounted() {
      this.getAllEmployee();
      this.getAttendanceTableDate();
    },
    created() {

    }
  }
</script>
<style lang="less" scoped
  .box-card {
    margin: 10px;
  }
</style>

效果图:
在这里插入图片描述

  • 2
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

CXY_BOY

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值