首页 > 解决方案 > 数据库中的值数组,每小时(制作图表)

问题描述

我想根据用户活动制作图表。在我的用户表中,我有一个时间戳字段,当用户点击新闻提要时该字段会更新。该图表将显示每小时有多少用户处于活动状态(即此时点击了提要)。

我需要这样的结果:[10,23,8,31,12];

10 = 上午 8 点到上午 9 点的连接用户数 23 = 9 到 10 连接的用户数 这是一个例子,我还需要一张带有时间的表

[0h, 1h, 2h, 3h, 4h, ...., 22h, 23h];

以下是图表的生成方式(您将理解上表的原因):

public function build(): \ArielMejiaDev\LarapexCharts\AreaChart
    {
        return $this->chart->areaChart()
            ->setTitle('User Activity')
            ->addData('Users', [40, 93, 35, 42, 82])
            ->setFontFamily('Poppins')
            ->setColors(['#FF886C', '#ff6c73'])
            ->setXAxis(['0h', '6h', '12h', '18h', '0h']);
    }

这是用户表,我感兴趣的字段是 "last_seen_feed" :

Schema::create('users', function (Blueprint $table) {
            $table->uuid('id')->primary();

            $table->foreignUuid('rank_id')->constrained('ranks');

            $table->string('username');
            $table->string('email');
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password');
            $table->integer('status')->default(0);
            $table->timestamp('last_seen_feed')->default(Carbon::now()->toDateTimeString());

            $table->rememberToken();
            $table->timestamps();
        });

提前感谢那些愿意花时间帮助我以表格形式检索他的数据的人,需要 2 个。

(PS:我使用这个包:ArielMejiaDev\LarapexCharts)

标签: laravel

解决方案


推荐阅读