duanlu4371 2019-04-22 13:05
浏览 33

如何修复“NULL不是有效的DataTable。” - Laravel Lavacharts

I have my data in an array and I'm trying to display the information in a Lavacharts Donut Chart, I've hit a wall since I'm not sure why it is erroring out, when I dump the variable ($counted_heroes) it looks fine but I'm not an expert with arrays.

I have googled the error but it only lead to a github issues page where it was unfortunately never resolved, I've looked at the Laravel "arguments" section of the error to see why it is erroring, it looks fine from my perspective with no empty values.

function index()
{
    $heroes = \Lava::DataTable();
    $heroes = DB::table('replays')->leftJoin('heroes', 'heroes.id', '=', 'replays.hero_id')->select(DB::raw('replays.hero_id as hero_id, heroes.hero_name as hero_name'))->get()->toArray();
    foreach($heroes as & $hero) {
        $hero = ['hero' => $hero->hero_name, $hero->hero_id, ];
    }

    $counted_heroes = array_count_values(array_column($heroes, 'hero'));
    \Lava::DonutChart('Heroes', $counted_heroes, ['title' => 'Heroes Played']);
    return view('public.stats', compact('lava'));
}

The expected outcome of this would be that the array is accepted by the Lavachart and the data is displayed, instead of this unfortunate error.

Any help would be most appreciated! <3

Thank you.

  • 写回答

1条回答 默认 最新

  • dongtan5555 2019-04-22 13:27
    关注

    compact() assumes that $compact variable is defined before.

    You didn't defined it inside your index() method.

    Try return view('public.stats', compact('heroes'));, your view is expecting not an array, but a certain library object, as it was mentioned by ourmandave. Note, that you have to replace lava to heroes in your view than.

    评论

报告相同问题?

悬赏问题

  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害