我在将json数据从控制器传递到morris条形图时遇到了问题,
这是我的控制器
$hits = Tourism::get([
\DB::raw('nama as nama'),
\DB::raw('jumlahview as jumlahview')
])->toJson();
这是刀片
<div class="panel-body">
<div id="pageHits"></div>
</div>
<script>
var data =JSON.parse('{{$hits}}}');
Morris.Bar({
element: 'pageHits',
data: data,
xkey: 'nama',
ykeys: 'jumlahview',
labels: ['Tourism'],
hideHover: 'auto',
resize: true
});
</script>
这是$ hits的值
[{"nama":"test1","jumlahview":10},{"nama":"palace","jumlahview":5}]
传递给视图
<div class="panel-body">
<div id="morris-pagehits"></div>
</div>
感谢