忽略数据库ConsoleTvs图表中的Null值

时间:2017-06-04 21:00:28

标签: mysql laravel-5 charts highcharts

所以我有一组需要在管理仪表板上显示的数据。 我决定使用Erik Campobadal的laravel图表包ConsoleTvs Charts。

我正在使用上面的包直接从数据库创建图表,问题是,在我的表(例如用户的表)中有列值为NULL。

如何忽略此空值并仅表示我的图表中具有实际值的列?

`
 $chart_print_media = Charts::database(User::all(), 'pie', 'highcharts')
                ->title('Print Media Campaign')
                ->dimensions(450, 300)
                ->groupBy('print_media',null);`

1 个答案:

答案 0 :(得分:0)

Thanks to Eric Campobadal, am just going to post the answer here for anyone that this might help in the future.

`

$users_print = User::all()->filter(function ($user) {
                return $user->print_media !== null;
            });


            $chart_print_media = Charts::database($users_print, 'pie', 'highcharts')
                ->title('Print Media Campaign')
                ->dimensions(450, 300)
                ->groupBy('print_media');

`

I believe this is self-explanatory enough