duanniling0018 2017-04-04 03:45
浏览 38

在laravel 5.2上使用Lavachart的月份图形计数

Hello i get stuck on this proble, hope you guys can give me some advice to solve this matter. So, i want to show graph that count basen on month, how many keluhan (complain) on that month. so the table will be like january has 3 complain, febuary has 5 complain, etc (example)

public function lihatkeluhan(){
    $halaman="tindaklayanan";
    $keluhan_list=DB::table('keluhans')
    ->select(DB::raw('id,tanggal,produk,username,area,masalah,status'))->get();

    $count = count($keluhan_list); //this still not count based on month
    $population = Lava::DataTable();
    $population->addDateColumn('Year')
               ->addNumberColumn('Keluhan')
               ->addRow(['?',$count]);

    Lava::LineChart('Population', $population, [
        'title' => 'Tahun : 2017',
        ]);

    return view('layanankonsumen.daftarkeluhan',compact('halaman','keluhan_list','lava'));
}
  • 写回答

1条回答 默认 最新

  • doure5236 2017-04-04 04:43
    关注

    try query like this. it will gives you groupby result with count of that particular month, no need for $count = count($keluhan_list); because you will get count in result.

    $keluhan_list=DB::table('keluhans')
        ->select(DB::raw('id,tanggal,produk,username,area,masalah,status,count(*) as count'))
        ->get()
        ->groupBy(function($date) {
              return Carbon::parse($date->created_at)->format('m'); // grouping by months
         });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看