vue實(shí)現(xiàn)折線圖 可按時(shí)間查詢
本文實(shí)例為大家分享了vue實(shí)現(xiàn)可按時(shí)間查詢的折線圖的具體代碼,供大家參考,具體內(nèi)容如下
1.vue前端
//查詢條件 <template> <el-date-picker v-model="listQuery.toptime" :picker-options="pickerOptions" style="width: 380px" type="daterange" clearable range-separator="至" start-placeholder="開(kāi)始日期" end-placeholder="結(jié)束日期"/> <el-select v-model="listQuery.xAxis" placeholder="統(tǒng)計(jì)粒度" clearable style="width: 150px" > <el-option v-for="(item, index) in xAxisList" :key="index" :label="item.value" :value="item.id" /> </el-select> //折線圖 <el-card class="box-card"> <div slot="header" class="clearfix"> <span>折線圖</span> </div> <div id="myChart3" :style="{width: '1400px', height: '600px'}"/> </el-card> </template>
2.對(duì)應(yīng)script代碼
// 引入基本模板 const echarts = require('echarts/lib/echarts') // 引入柱狀圖組件 require('echarts/lib/chart/bar') require('echarts/lib/chart/pie') // 引入提示框和title組件 require('echarts/lib/component/tooltip') require('echarts/lib/component/title') require('echarts/lib/component/legend') export default { data() { return { listQuery: { page: 0, limit: 20, toptime: null, xAxis: null }, XList: [], XListName: '', YList: [], YListName: '', xAxisList: [ { id: 1, value: '年' }, { id: 2, value: '月' }, { id: 3, value: '周' } ], temp: { id: undefined, } } }, methods: { handleFilter1() { const listQueryData = Object.assign({}, this.listQuery) if (listQueryData.toptime !== null) { listQueryData.toptime = JSON.stringify(this.listQuery.toptime) } else if (listQueryData.toptime === null) { const end = new Date() const start = new Date() start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)//默認(rèn)按周查詢 this.listQuery.toptime = [start, end] listQueryData.toptime = JSON.stringify([start, end]) } switch (listQueryData.xAxis) { case 1: { const end = new Date() const start = new Date() start.setTime(start.getTime() - 3600 * 1000 * 24 * 365)//按年查詢 this.listQuery.toptime = [start, end] listQueryData.toptime = JSON.stringify([start, end]) break } case 2: { const end = new Date() const start = new Date() start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)//按月查詢 this.listQuery.toptime = [start, end] listQueryData.toptime = JSON.stringify([start, end]) break } case 3: { const end = new Date() const start = new Date() start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)//按周查詢 this.listQuery.toptime = [start, end] listQueryData.toptime = JSON.stringify([start, end]) break } } getShareTripCount(listQueryData).then(response => { this.XList = response.data.data.XList this.YList = response.data.data.YList this.YListName = response.data.data.YListName this.XListName = response.data.data.XListName this.drawLine() }) }, //重點(diǎn) drawLine() { const myChart3 = echarts.init(document.getElementById('myChart3')) myChart3.showLoading() // 數(shù)據(jù)加載完之前先顯示一段簡(jiǎn)單的loading動(dòng)畫 myChart3.hideLoading() // 隱藏加載動(dòng)畫 // 繪制折線圖 const option = { title: { text: '分享行程數(shù)據(jù)統(tǒng)計(jì)', subtext: '' }, // tooltip: { // trigger: 'axis' // }, legend: { data: ['總分享次數(shù)', '通過(guò)分享注冊(cè)用戶數(shù)', '今日分享次數(shù)', '今日通過(guò)注冊(cè)分享數(shù)'] }, // toolbox: { // show: true, // feature: { // mark: { show: true }, // dataView: { show: true, readOnly: false }, // magicType: { show: true, type: ['line', 'bar'] }, // restore: { show: true }, // saveAsImage: { show: true } // } // }, calculable: true, xAxis: { name: this.XListName, type: 'category', data: this.XList }, yAxis: { name: this.YListName, type: 'value' }, series: [ { name: '總分享次數(shù)', type: 'line', data: this.YList.sharenumList // markPoint: { // data: [ // { type: 'max', name: '最大值' }, // { type: 'min', name: '最小值' } // ] // } // markLine: { // data: [ // { type: 'average', name: '平均值' } // ] // } }, { name: '通過(guò)分享注冊(cè)用戶數(shù)', type: 'line', data: this.YList.shareUserRegisterList // markPoint: { // data: [ // { type: 'max', name: '最大值' }, // { type: 'min', name: '最小值' } // ] // } // markLine: { // data: [ // { type: 'average', name: '平均值' } // ] // } }, { name: '今日分享次數(shù)', type: 'line', data: this.YList.shareNumByDayList // markPoint: { // data: [ // { name: '周最低', value: -2, xAxis: 1, yAxis: -1.5 } // ] // } // markLine: { // data: [ // { type: 'average', name: '平均值' } // ] // } }, { name: '今日通過(guò)注冊(cè)分享數(shù)', type: 'line', data: this.YList.shareUserRegisterByDayList // markPoint: { // data: [ // { name: '周最低', value: -2, xAxis: 1, yAxis: -1.5 } // ] // } // markLine: { // data: [ // { type: 'average', name: '平均值' } // ] // } } ] } myChart3.setOption(option) } } }
3.對(duì)應(yīng)后端controller代碼
@RequestMapping(value = "/getShareTripCount", method = RequestMethod.POST) @ResponseBody public JSONResult getShareTripCount(HttpServletRequest request) { try { String topTime = request.getParameter("toptime"); String xAxis = request.getParameter("xAxis"); Map map = new HashMap(); if(!StringUtils.isEmpty(xAxis)){ switch (xAxis){ case "1":{ break; } case "2":{ map= getShareTripCountByTime(topTime); break; } case "3":{ map= getShareTripCountByTime(topTime); break; } default:{ map= getShareTripCountByTime(topTime); break; } } }else{ map=getShareTripCountByTime(topTime); } return new JSONResult(map, 0, "成功", true); } catch (Exception e) { e.printStackTrace(); return new JSONResult(null, 101, "服務(wù)器獲取失敗", false); } } private Map getShareTripCountByTime(String topTime) throws ParseException { Map map=new HashMap(); Sort.Order so = new Sort.Order(Sort.Direction.DESC, "id"); Sort sort = new Sort(so); if (!StringUtils.isEmpty(topTime)) { topTime = topTime.replace("Z", " UTC"); Gson gson = new Gson(); List<String> timeList = gson.fromJson(topTime, new TypeToken<List<String>>() { }.getType()); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS Z"); Date endTime = format.parse(timeList.get(1)); Date beginTime = format.parse(timeList.get(0)); List<ShareCount> shareCountList = mongoTemplate.find(Query.query(Criteria.where("createTime").gte(beginTime).lte(endTime)).with(sort), ShareCount.class); Calendar c = Calendar.getInstance(); c.setTime(beginTime); int month = c.get(Calendar.MONTH); int year = c.get(Calendar.YEAR); int day = c.get(Calendar.DATE); int dayMax = DateUtil.daysBetween(beginTime, endTime); List<String> dayList = new ArrayList<>(); int monthMaxDay = DateUtil.getDaysByYearMonth(year, month); List<String> sharenumList = new ArrayList<>(); List<String> shareUserRegisterList = new ArrayList<>(); List<String> shareNumByDayList = new ArrayList<>(); List<String> shareUserRegisterByDayList = new ArrayList<>(); int j = 1; for (int i = 1; i <= dayMax; i++) { String sub = ""; int yue; int di; if (monthMaxDay >= i + day) { di = day + i; yue = month + 1; sub = yue + "-" + di; } else { yue = month + 2; di = j; sub = yue + "-" + di; j++; } int sharenum = 0; String sharenums =""; int shareUserRegister = 0; String shareUserRegisters =""; int shareNumByDay = 0; String shareNumByDays =""; int shareUserRegisterByDay = 0; String shareUserRegisterByDays =""; for (ShareCount shareCount : shareCountList) { c.setTime(shareCount.getCreateTime()); int months = c.get(Calendar.MONTH) + 1; int years = c.get(Calendar.YEAR); int days = c.get(Calendar.DATE); if (year == years && yue == months && di == days) { sharenum = sharenum + shareCount.getShareNum(); shareUserRegister = shareUserRegister + shareCount.getShareUserRegister(); shareNumByDay=shareNumByDay+ shareCount.getShareNumByDay(); shareUserRegisterByDay=shareUserRegisterByDay+shareCount.getShareUserRegisterByDay(); } } sharenums=String.valueOf(sharenum); shareUserRegisters=String.valueOf(shareUserRegister); shareNumByDays=String.valueOf(shareNumByDay); shareUserRegisterByDays=String.valueOf(shareUserRegisterByDay); dayList.add(sub); sharenumList.add(sharenums); shareUserRegisterList.add(shareUserRegisters); shareNumByDayList.add(shareNumByDays); shareUserRegisterByDayList.add(shareUserRegisterByDays); } Map maps=new HashMap(); maps.put("sharenumList", sharenumList); maps.put("shareUserRegisterList", shareUserRegisterList); maps.put("shareNumByDayList", shareNumByDayList); maps.put("shareUserRegisterByDayList", shareUserRegisterByDayList); map.put("type", "month"); map.put("YList", maps); map.put("YListName", "次"); map.put("XListName", "日期"); map.put("XList", dayList); } return map; }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- vue+echart實(shí)現(xiàn)圓滑折線圖
- VUE項(xiàng)目中封裝Echart折線圖的方法
- Vue+Echarts實(shí)現(xiàn)柱狀折線圖
- Vue+Echarts實(shí)現(xiàn)簡(jiǎn)單折線圖
- vue+echarts實(shí)現(xiàn)多條折線圖
- vue使用echarts實(shí)現(xiàn)折線圖
- vue使用ECharts實(shí)現(xiàn)折線圖和餅圖
- vue+echarts實(shí)現(xiàn)動(dòng)態(tài)折線圖的方法與注意
- 在vue中使用echarts(折線圖的demo,markline用法)
- vue+echarts實(shí)帶漸變效果的折線圖
相關(guān)文章
vue中在vuex的actions中請(qǐng)求數(shù)據(jù)實(shí)例
今天小編就為大家分享一篇vue中在vuex的actions中請(qǐng)求數(shù)據(jù)實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-11-11Vue+ElementUI實(shí)現(xiàn)表單動(dòng)態(tài)渲染、可視化配置的方法
這篇文章主要介紹了Vue+ElementUI實(shí)現(xiàn)表單動(dòng)態(tài)渲染、可視化配置的方法,需要的朋友可以參考下2018-03-03vue使用this.$message不生效的部分原因及解決方案
這篇文章主要介紹了vue使用this.$message不生效的部分原因及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-09-09基于vue 實(shí)現(xiàn)表單中password輸入的顯示與隱藏功能
這篇文章主要介紹了vue 實(shí)現(xiàn)表單中password輸入的顯示與隱藏功能 ,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-07-07vue跳轉(zhuǎn)頁(yè)簽傳參并查詢參數(shù)的保姆級(jí)教程
這篇文章主要介紹了vue跳轉(zhuǎn)頁(yè)簽傳參并查詢參數(shù)的保姆級(jí)教程,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-04-04詳解最新vue-cli 2.9.1的webpack存在問(wèn)題
這篇文章主要介紹了最新vue-cli 2.9.1的webpack存在問(wèn)題,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-12-12vue+golang實(shí)現(xiàn)上傳微信頭像功能
這篇文章主要介紹了vue+golang實(shí)現(xiàn)上傳微信頭像功能,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2023-10-10