Javascript 从数据库到js图表的数据
我有一个用highcharts构建的javascript图表,我会在图表中显示数据库中的数据。 我需要显示一周中每一天的数据。我用的是laravel,所以我可以用碳,但我不知道怎么用。 以下是我的看法:Javascript 从数据库到js图表的数据,javascript,php,database,laravel,highcharts,Javascript,Php,Database,Laravel,Highcharts,我有一个用highcharts构建的javascript图表,我会在图表中显示数据库中的数据。 我需要显示一周中每一天的数据。我用的是laravel,所以我可以用碳,但我不知道怎么用。 以下是我的看法: <div id="container"></div> <script> $(function () { $('#container').highcharts({ chart: { type
<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。。。
谢谢大家。我发现这个小教程可能对你有帮助。。。请参阅本文档:http://www.highcharts.com/docs/working-with-data/preprocessing-data-from-a-databaseThanks.I 阅读te教程。但我的问题是从数据库中检索一周中每一天的数据。我不确定您的报告应该是什么样子,但听起来您需要使用DAYOFWEEK,但不确定它是一个select还是按它分组,我假设为select。Actionshistory::selectDB::raw'DAYOFWEEKcreated_at'、'some_other_column'->get@用户3158900谢谢!我用0=星期一,1=星期二,ecc。。。