laravel - 数据库中的值数组,每小时(制作图表)
问题描述
我想根据用户活动制作图表。在我的用户表中,我有一个时间戳字段,当用户点击新闻提要时该字段会更新。该图表将显示每小时有多少用户处于活动状态(即此时点击了提要)。
我需要这样的结果:[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)
解决方案
推荐阅读
- electron - 如何使用电子存储将对象插入到对象数组中
- python - 通过一行和每个列名迭代数据框并为 bkoeh-heatmap 填充新数据框
- distance - 计算点云中所有对的测地距离
- c# - 将打字稿(列表)转换为 C# 列表?
- php - 条件如果使用 ajax 和 php 返回 true,即使它是 false
- razor - 检查字符串是否是 Razor 中的数字
- python - 如何将具有多个逗号的列从 csv 插入到表中
- mongodb - Mongodb $cond 与查找
- android - 我如何使用 CameraKit 保存视频
- python - 在 tf.session() 中更改张量的值