在這篇文章中,我給大家分享的內容是關於利用laravel框架來實現一個數據統計圖,程式碼很清晰,有一定的參考價值,希望可以幫助到有需要的朋友。
#使用vue-highcharts
<highcharts></highcharts>
data() { return { options: { title: { text: '' }, xAxis: { categories: [] }, yAxis: { title: { text: '' }, plotLines: [{ value: 0, width: 1, color: '#808080' }] }, legend: { layout: 'horizontal', align: 'center', verticalAlign: 'bottom', borderWidth: 0 }, credits: { enabled: false // 去掉highcharts商标 }, series: [] } } },
請求數據處理:
getTimingHistoryAct(time) { getTimingHistory(time).then(response => { const curHour = new Date().getHours() const hoursArr = [] const dayArr = [] const seriesData = [] switch (time) { case 1: seriesData.length = 0 for (let i = 0; i x + ':00') response.data.forEach(record => { const index = hoursArr.indexOf(record.hour) if (index > -1) { seriesData[index] = record.count } }) break case 7: seriesData.length = 0 for (let i = 0; i x.substr(5)) response.data.forEach(record => { const index = dayArr.indexOf(record.date) if (index > -1) { seriesData[index] = record.count } }) break case 30: // 同7天 break } this.options.series = [{ name: '商品点击', data: seriesData }] }) },
mysql測試資料:
1 5440935 1php中文网 2018-07-28 19:20:49 2 5440935 1 php中文网 2018-07-29 15:26:21 3 5440935 1 测试方案1 2018-07-29 15:38:43 ...
public function getTimingHistory($time) { switch ($time) { case '1': $data = StatsPlanClick::where('created_at','where('created_at','>', Carbon::today())->select([DB::raw('DATE_FORMAT(created_at,\'%H\') as hour'), DB::raw('COUNT("*") as count')])->groupBy('hour')->get(); break; case '7': $data = StatsPlanClick::where('created_at','where('created_at','>', Carbon::today()->subDays(7))->select([DB::raw('DATE(created_at) as date'), DB::raw('COUNT("*") as count')])->groupBy('date')->get(); break; case '30': $data = StatsPlanClick::where('created_at','where('created_at','>', Carbon::today()->subDays(30))->select([DB::raw('DATE(created_at) as date'), DB::raw('COUNT("*") as count')])->groupBy('date')->get(); break; default: # code... break; } return $this->successWithData($data); }
以上就是本篇文章的全部內容了,更多laravel內容請關注laravel框架入門教程。
相關文章推薦:
##即時聊天室:基於Laravel Pusher Vue透過事件廣播實作##相關課程推薦:
2017年最新的五個Laravel影片教學推薦#以上是laravel框架在資料統計繪圖的實現的詳細內容。更多資訊請關注PHP中文網其他相關文章!