這篇文章主要介紹Echarts教程之如何通過Ajax實現動態(tài)加載折線圖,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
一、GIF圖
二、前臺代碼
// 調用方法 hotlineLine(); // 定時刷新 setInterval(function () { hotlineLine(); },5000); function hotlineLine(){ // 初始化圖表元素 var hotlineLine = echarts.init(document.getElementById('hotlineLine_id')); $.get('${pageContext.request.getContextPath()}/m/hotline.do', function (res) { var option = { // 提示框組件,鼠標經過餅圖時會出現提示框 tooltip: { // 觸發(fā)類型 // 坐標軸觸發(fā),主要在柱狀圖,折線圖等會使用類目軸的圖表中使用。 trigger: 'axis' }, // 每條折線的顏色 color: ['#87CEFA', '#9AFF9A', '#C0FF3E','#DB7093'], // 圖例組件 legend: { // 內容 data:['呼入', '呼出', '應答', '用戶放棄'], // 樣式 textStyle:{ fontSize:10, color:'#66ffff' }, // 上距離,類似css中的margin top:'5%' }, // 網格 grid: { // 左距離 left: '7%', right: '5%', bottom: '10%', top:'20%' }, // 橫坐標 xAxis: { // 類型 type: 'category', // 刻度 data: ['08:00', '10:00', '12:00', '14:00', '16:00', '18:00', '20:00', '22:00', '24:00'], // 樣式 axisLine:{ // 橫坐標線的顏色 lineStyle:{ color:'#66ffff' } } }, yAxis: { type: 'value', name: '次數', axisLabel: { formatter: '{value}' }, axisLine:{ lineStyle:{ color:'#66ffff' } }, splitLine:{ show: true, lineStyle:{ color:'#66ffff' } } }, series: [ { name:'呼入', type:'line', data:res[3] }, { name:'呼出', type:'line', data:res[2] }, { name:'應答', type:'line', data:res[1] }, { name:'用戶放棄', type:'line', data:res[0] } ], // 文本標簽 label: { //是否展示 show: true, position: 'top', textStyle: { fontWeight:'bolder', fontSize : '12', fontFamily : '微軟雅黑', color:defaultColor } } }; hotlineLine.setOption(option); }); } <div class="rightMain01-sub03 box-border"> <div class="box-title">話務指標趨勢圖</div> <div class="rightMain01-sub03-data"> <div id="hotlineLine_id" ></div> </div> </div>
三、后臺代碼
List<List<Integer>> hotlineList = new ArrayList<List<Integer>>(); @RequestMapping("/m/hotline.do") @ResponseBody public JSONArray hotline() { List<List<Integer>> returnList = new ArrayList<List<Integer>>(); if (hotlineList.size() == 0 || hotlineList.get(0).size() >= 9) { hotlineList.clear(); for (int i = 0; i < 4; i++) { List<Integer> l = new ArrayList<Integer>(); l.add(i * 5 + AlexUtils.getRandomInteger(0, 5)); hotlineList.add(l); } } for (int i = 0; i < hotlineList.size(); i++) { List<Integer> list = hotlineList.get(i); int thisSize = list.size(); if (thisSize < 5) { list.add(list.get(thisSize - 1) + AlexUtils.getRandomInteger(1, 5)); } else { list.add(list.get(thisSize - 1) - AlexUtils.getRandomInteger(1, 5)); } returnList.add(list); } hotlineList = returnList; return JSONArray.fromObject(returnList); } public static int getRandomInteger(int min, int max) { int diff = max - min; return min + new Random().nextInt(diff); }
數據格式:
1.[[1,3,4,5,7],[6,9,11,12,13],[10,11,12,13,16],[16,19,21,22,24]]
ajax是一種在無需重新加載整個網頁的情況下,能夠更新部分網頁的技術,可以通過在后臺與服務器進行少量數據交換,使網頁實現異步更新。
以上是“Echarts教程之如何通過Ajax實現動態(tài)加載折線圖”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注創(chuàng)新互聯行業(yè)資訊頻道!
網站標題:Echarts教程之如何通過Ajax實現動態(tài)加載折線圖-創(chuàng)新互聯
轉載來于:http://aaarwkj.com/article26/dspscg.html
成都網站建設公司_創(chuàng)新互聯,為您提供網站內鏈、網站收錄、云服務器、網站排名、營銷型網站建設、手機網站建設
聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯