[英]Passing Labels from PHP to Chart.js
I'm trying to pass a list of names into the labels section of a Chart.js chart which I'm retrieving from a database with PHP. 我试图将名称列表传递到Chart.js图表的标签部分,该图表是使用PHP从数据库中检索的。
In my controller I do 在我的控制器中
json_encode(array_pluck($var->toArray(), 'name'));
which returns: 返回:
"["name1","name2","name3","name4","name5","name6"]"
In the view, I have: 我认为:
labels: {{ $var }},
and when I view the source, I can see 当我查看源代码时,我可以看到
"name1","name2","name3","name4","name5","name6"
This is causing the chart to fail as it's expecting: 这导致图表按预期失败:
'name1','name2','name3','name4','name5','name6'
I've tried various things such as html_entity_decode
, json_decode
and htmlspecialchars_decode
but not of them seem to do anything. 我已经尝试了各种东西,如html_entity_decode
, json_decode
和htmlspecialchars_decode
但不是他们似乎无所不能。
You have to use {!! $assets_by_department_departments !!}
您必须使用{!! $assets_by_department_departments !!}
{!! $assets_by_department_departments !!}
- This will prevent Blade from escaping the data. {!! $assets_by_department_departments !!}
-这将防止Blade逃逸数据。
See https://laravel.com/docs/5.6/blade#displaying-data for further details :) 有关更多详细信息,请参见https://laravel.com/docs/5.6/blade#displaying-data :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.