laravel + vue實(shí)現(xiàn)的數(shù)據(jù)統(tǒng)計(jì)繪圖(今天、7天、30天數(shù)據(jù))
前言
本文主要是按照時(shí)段統(tǒng)計(jì)今天、7天、30天的數(shù)據(jù),利用laravel+vue實(shí)現(xiàn)的,下面話(huà)不多說(shuō)了,來(lái)一起看看詳細(xì)的介紹吧
效果圖:
1. 前端vue
使用vue-highcharts
<highcharts :options="options"></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商標(biāo) }, series: [] } } },
請(qǐng)求數(shù)據(jù)處理:
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 <= curHour; i++) { hoursArr.push(i < 10 ? '0' + i : '' + i) seriesData[i] = 0 } this.options.xAxis.categories = hoursArr.map(x => 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 < 7; i++) { const ymd = new Date(new Date() - 24 * 60 * 60 * 1000 * i).toLocaleString().split(' ')[0] const ymdarr = ymd.split('/') if (ymdarr[1] * 1 < 10) { ymdarr[1] = '0' + ymdarr[1] } if (ymdarr[2] * 1 < 10) { ymdarr[2] = '0' + ymdarr[1] } seriesData[i] = 0 dayArr.unshift(ymdarr.join('-')) } this.options.xAxis.categories = dayArr.map(x => 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: '商品點(diǎn)擊', data: seriesData }] }) },
2. 后臺(tái)laravel
mysql測(cè)試數(shù)據(jù):
1 5440935 1 時(shí)尚博主家《心之語(yǔ)》 2018-07-28 19:20:49
2 5440935 1 時(shí)尚博主家《心之語(yǔ)》 2018-07-29 15:26:21
3 5440935 1 測(cè)試方案1 2018-07-29 15:38:43
...
public function getTimingHistory($time) { switch ($time) { case '1': $data = StatsPlanClick::where('created_at','<', Carbon::now())->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','<', Carbon::now())->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','<', Carbon::now())->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); }
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,如果有疑問(wèn)大家可以留言交流,謝謝大家對(duì)腳本之家的支持。
相關(guān)文章
關(guān)于UEditor編輯器遠(yuǎn)程圖片上傳失敗的解決辦法
因?yàn)閱渭兿矚g UEditor 的界面,于是把項(xiàng)目中原先的編輯器進(jìn)行的替換,但在后續(xù)操作中發(fā)現(xiàn)一些問(wèn)題,就是遠(yuǎn)程圖片上傳2012-08-08PHP如何實(shí)現(xiàn)阿里云短信sdk靈活應(yīng)用在項(xiàng)目中的方法
這篇文章主要介紹了PHP如何實(shí)現(xiàn)阿里云短信sdk靈活應(yīng)用在項(xiàng)目中的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2019-06-06實(shí)例介紹PHP中zip_open()函數(shù)用法
在本篇內(nèi)容里小編給大家分享了關(guān)于PHP中zip_open()函數(shù)用法的相關(guān)知識(shí)點(diǎn),有需要的朋友們跟著學(xué)習(xí)下。2019-02-02Laravel 微信小程序后端實(shí)現(xiàn)用戶(hù)登錄的示例代碼
這篇文章主要介紹了Laravel 微信小程序后端實(shí)現(xiàn)用戶(hù)登錄的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11ThinkPHP5 框架引入 Go AOP,PHP AOP編程項(xiàng)目詳解
這篇文章主要介紹了ThinkPHP5 框架引入 Go AOP,PHP AOP編程,結(jié)合具體項(xiàng)目項(xiàng)目分析了ThinkPHP5 引入 Go AOP,PHP AOP編程相關(guān)概念、原理、操作技巧與注意事項(xiàng),需要的朋友可以參考下2020-05-05yii實(shí)現(xiàn)model添加默認(rèn)值的方法(2種方法)
這篇文章主要介紹了yii實(shí)現(xiàn)model添加默認(rèn)值的方法,結(jié)合實(shí)例分析了在rules()方法及在beforeSave()方法中設(shè)定兩種實(shí)現(xiàn)技巧,需要的朋友可以參考下2016-01-01