我有一个用" highcharts"构建的javascript图表我会在图表中显示数据库中的数据。
我需要显示一周中每一天的数据。我使用laravel所以我可以使用Carbon,但我不知道怎么做。
以下是我的观点:
<div id="container"></div>
<script>
$(function () {
$('#container').highcharts({
chart: {
type: 'line'
},
title: {
text: 'Actions statistics'
},
xAxis: {
categories: ['01', '02', '03', '04', '05', '06', '07'] // days of the week
},
yAxis: {
title: {
text: 'Actions'
}
},
series: [{
name: 'Submitted actions',
data: [monday rows, tuesday rows, wednesday rows, thursday rows, friday rows, saturday rows, sunday rows]
// data can be retrieved from database where them are stored with "created at" column.
// Something like Actionshistory::where('created_at', first day of the week)?
}
]
});
});
</script>
我该怎么做?
感谢
解决
我在javascript中解决了这个问题:
series: [{
name: 'Actions submitted',
data: [<?php echo Actionshistory::whereRaw('WEEKDAY(created_at) = 0')->count() ?>,and so go on]
}
0 =星期一,1 =星期二,ecc ...... 谢谢大家。