我用laravel 5.3 aaand做一个项目 我想用https://erik.cat/projects/Charts/docs/4#installation创建一个图表,我希望它是动态的,标签字段是用户参与其任务的项目标题数组(希望我很清楚)
直到现在我有类似的东西
$idUser = Auth::user()->id;
$tasksUsed = DB::table('user_task')
->join('tasks', 'tasks.id', '=', 'user_task.task_id')
->join('projects', 'projects.id', '=', 'tasks.project_id')
->select('projects.title')->where('user_task.user_id',$idUser)->get();
// dd($tasksUsed->toArray());
$chart = Charts::create('donut', 'morris')
// ->view('custom.line.chart.view') // Use this if you want to use your own template
->title('My nice chart')
->labels($tasksUsed->toArray())
->values([3,4])
->dimensions(300,300)
->responsive(false);
它给了我这个错误,我不知道如何解决它
Method Illuminate\View\View::__toString() must not throw an exception, caught ErrorException: Object of class stdClass could not be converted to string
...\vendor\consoletvs\charts\resources\views\morris\donut.blade.php)
答案 0 :(得分:0)
我认为在donut.blade.php
你正在做这样的事情:
{!! $chart !!}
因为$chart
是一个对象,所以它不能打印为字符串
答案 1 :(得分:0)
$chart = Charts::create('donut', 'morris')
// ->view('custom.line.chart.view') // Use this if you want to use your own template
->title('My nice chart')
->labels($tasksUsed->pluck('title')->toArray())
->values([3,4])
->dimensions(300,300)
->responsive(false);
这是解决方案