您好,登錄后才能下訂單哦!
這篇文章主要介紹了laravel+vue實(shí)現(xiàn)數(shù)據(jù)統(tǒng)計(jì)繪圖的示例,具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
效果圖:
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í)尚博主家《心之語》 2018-07-28 19:20:49
2 5440935 1 時(shí)尚博主家《心之語》 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); }
感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“l(fā)aravel+vue實(shí)現(xiàn)數(shù)據(jù)統(tǒng)計(jì)繪圖的示例”這篇文章對(duì)大家有幫助,同時(shí)也希望大家多多支持億速云,關(guān)注億速云行業(yè)資訊頻道,更多相關(guān)知識(shí)等著你來學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。