我需要一个月的显示温度图,我的视图页面包含temp.blade。
<script>
console.log({!! $temp !!});
console.log({!! $dateTemp !!});
window.onload = function() {
var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: {!! $temp !!},
datasets: [{
label: 'Temperature',
data: {!! $dateTemp !!},
borderWidth: 1
}]
}
});
}
</script>和控制器
public function tempChart()
{
$temp = Temps::select(DB::raw('temp'))
->orderBy('date_temp','asc')
->get();
$temp->implode(',',$temp);
$dateTemp = Temps::select(DB::raw('temps'))
->select('date_temp')
->orderBy('date_temp','asc')
->get();
$dateTemp->implode(',',$dateTemp);
//dd($temp,$dateTemp);
return view('report/temp')
->with('temp',$temp)
->with('dateTemp',$dateTemp);
}它不能显示数据数组,但它显示
{.}{.}{.}
发布于 2017-10-04 06:54:58
我不确定您使用的是哪个图表库,但它们中的大多数都需要一个字符串或整数数组,然后给它们提供对象数组。
我认为您只需在php (或javescript)中转换数组即可。
php方式:
$temp = Temps::select('temp'`)
->orderBy('date_temp','asc')
->get()
->pluck('temp');
$dateTemp = Temps::select(['temps', 'data-temp'])
->orderBy('date_temp','asc')
->get()
->pluck('data-temp'); // I am not whats the acual query you want but this is the idea如果你用的是拉拉5.5就写在你的刀刃上
<script>
window.onload = function() {
var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: @json($temp),
datasets: [{
label: 'Temperature',
data: @json($dateTemp) ,
borderWidth: 1
}]
}
});
}
</script>发布于 2017-10-04 06:37:56
试着在数据中添加高逗号?
datasets: [{
label: 'Temperature',
data: '{!! $dateTemp !!}',
borderWidth: 1
}]https://stackoverflow.com/questions/46558351
复制相似问题