我有以下模型(下面的迁移)与访问我网站的国家/地区拉出图表。 我怎样才能拔出前10个国家? 谢谢
return Charts::database(Visit::all(), 'donut', 'highcharts')
->title('Requests by country')
->dimensions(700, 300)
->responsive(true)
->groupBy('country');
这是我的表
$table->increments('id');
$table->timestamp('timestamp');
$table->ipAddress('ip_address');
$table->string('city')->nullable();
$table->string('country')->nullable();
$table->string('details')->nullable();
答案 0 :(得分:0)
按顺序使用
return Charts::database(Visit::all(), 'donut', 'highcharts')
->title('Requests by country')
->dimensions(700, 300)
->responsive(true)
->groupBy('country')
->orderBy('column_name','asc')
->take(10);
答案 1 :(得分:0)
尝试传递已经过滤的信息,如下所示:
$info = DB::table('visits')
->select(DB::raw('count(*) as country_count, country'))
->groupBy('country')
->orderBy('country_count', 'desc')
->take(10)
->get();
return Charts::database($info, 'donut', 'highcharts')
->title('Requests by country')
->dimensions(700, 300)
->responsive(true);