Vue 中使用echart循环遍历动态使用x,y坐标轴

本文介绍了一种基于ECharts的网站统计分析方法,通过实时更新的报表展示网站的访问量PV、UV,以及近7天的访问量峰值。同时,文章详细描述了如何使用Vue.js和Element UI构建统计页面,包括数据的获取、处理和图表的绘制过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<template>
<el-container class="page-wrap">
    <el-header class="page-nav" height="30px">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>统计分析</el-breadcrumb-item>
        <el-breadcrumb-item>报表统计</el-breadcrumb-item>
      </el-breadcrumb>
    </el-header>
    <el-main class="page-main">
       <el-row :gutter="20" type="flex" justify="center">
          <el-col :span="6">
            <el-card :body-style="{ padding: '0px' }">             
              <div style="padding: 14px;">
                <span>今日访问量pv</span>
                <div class="bottom clearfix">
                  <div class="time" style="font-size: 20px;text-align:center">{{ todayPvCount }}</div>
                  <!--<el-button type="text" style="float:right" class="button">操作按钮</el-button>-->
                </div>
              </div>
            </el-card>
          </el-col>
          <el-col :span="6">
            <el-card :body-style="{ padding: '0px' }">             
              <div style="padding: 14px;">
                <span>今日访问量uv</span>
                <div class="bottom clearfix">
                   <div class="time" style="font-size: 20px;text-align:center">{{ todayUvCount }}</div>
                  <!--<el-button type="text" class="button">操作按钮</el-button>-->
                </div>
              </div>
            </el-card>
          </el-col>
          <el-col :span="6">
            <el-card :body-style="{ padding: '0px' }">             
              <div style="padding: 14px;">
                <span>近7天访问量峰值</span>
                <div class="bottom clearfix">
                   <div class="time" style="font-size: 20px;text-align:center">时间:{{laterTime}} 数量:{{ laterCount }}</div>
                  <!---<el-button type="text" class="button">操作按钮</el-button>-->
                </div>
              </div>
            </el-card>
          </el-col>
       </el-row>
       <!--<el-row :gutter="20" >
         <el-card class="box-card" style="float: left; border-width:2px" shadow="always" v-for = "w in datas.length" :key="w">
            <div slot="header" class="clearfix">
                <span>{{ datas[w-1].id }} </span>
                <el-button style="float: right; padding: 3px 0" type="text">详情</el-button>
            </div>
            <div v-for="o in 4" :key="o" class="text item">
                {{'列表内容 ' + o }}
            </div>
        </el-card>
     </el-row>-->
      <el-row :gutter="30">
        <el-card class="box-card" style="float: left"  shadow="always">
          <div id="chartDay" :style="{width: '300px', height: '300px'}"></div>
        </el-card>      
      </el-row>
    </el-main>
  </el-container>
</template>
<script>

import DxInput from "../../../Common/ui/unit/dx-input";
import http from '../../../../assets/js/http'

export default {
    components : {
        DxInput,
    },
    data (){
        return {
          datas: [
              {"id" : "one"},
              {"id" : "two"}
          ],
          todayPvCount:0,
          todayUvCount:0,
          laterTime:'',
          laterCount:0,
          countMonth:[],
          currentDate: new Date()
        }
    },
    methods: {
        test(){
          let date = new Date();
          let dates = moment(date).format('YYYY-MM-DD HH:mm:ss');
          console.log(dates);
        },
       
        getDayCount(){
          let data = {}
           data = {
             params: {
                 inputTime: "2019-03-13",
                 flag: "pv"
             }
           },
           this.apiGet('/jboot/elastic/queryCountForDay',data).then((res) =>{
              if(res.state === "ok"){                
                 this.drawDayLine(res.data)
              }else{
                 _g.toastMsg('warning', "请求失败")
              }
           })
        },
       
        drawDayLine(data){
            // 基于准备好的dom,初始化echarts实例
            let myChart = this.$echarts.init(document.getElementById('chartDay'));
            // 绘制图表
            let datas = data;
            let xdata=[];
            var ydata=[];
            for(var i = 0;i<datas.length;i++){
                      xdata.push(moment(datas[i].inputTime ).format('MM-DD'));
                      ydata.push(datas[i].count);
            };        
            myChart.setOption({
                title: { text: '每日数据量统计' },
                tooltip: {},
                xAxis: {              
                  data:xdata
                },
                yAxis: {},
                series: [{
                    name: '访问量',
                    type: 'bar',
                    data: ydata
                }]
            });
       }
       

    },
    created(){
      
         this.test();
       
    },
    mounted(){
          this.getDayCount();
          
    },
     mixins: [http]
}
</script>
<style scoped>

  .el-row {
    margin-bottom: 20px;
    &:last-child {
      margin-bottom: 0;
    }
  }
  .text {
    font-size: 14px;
  }

  .item {
    margin-bottom: 18px;
  }

  .clearfix:before,
  .clearfix:after {
    display: table;
    content: "";
  }
  .clearfix:after {
    clear: both
  }

  .box-card {
    width: 480px;
  }
  .time {
    font-size: 13px;
    color: #FF0000;
   
  }
</style>

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

伏特加的滋味

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

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

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

打赏作者

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

抵扣说明:

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

余额充值