久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

Echarts  java 后臺交互

 yan的圖書41 2015-07-14

jsp頁面

  1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>  

  2. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www./TR/html4/loose.dtd">  

  3. <html>  

  4. <head>  

  5. <title>line</title>  

  6. <script type="text/javascript" src="${pageContext.request.contextPath}/js/echarts2.0/esl.js"></script>  

  7. <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.8.3.js"></script>  

  8. </head>  

  9. <body>  

  10.     <!-- 為ECharts準(zhǔn)備一個具備大?。▽捀撸┑腄om -->  

  11.         <div id="main" style="height:400px"></div>  

  12.     <script type="text/javascript" language="javascript">  

  13.         var myChart;  

  14.         var eCharts;  

  15.         require.config({  

  16.             paths : {  

  17.                 'echarts' : '${pageContext.request.contextPath}/js/echarts2.0/echarts' ,  

  18.                 'echarts/chart/line' : '${pageContext.request.contextPath}/js/echarts2.0/echarts' //需要的組件  

  19.             }  

  20.         });  

  21.         require(  

  22.             [ 'echarts',   

  23.               'echarts/chart/line'  

  24.             ], DrawEChart //異步加載的回調(diào)函數(shù)繪制圖表  

  25.         );  

  26.         //創(chuàng)建ECharts圖表方法  

  27.         function DrawEChart(ec) {  

  28.             eCharts = ec;  

  29.             myChart = eCharts.init(document.getElementById('main'));  

  30.             myChart.showLoading({  

  31.                 text : "圖表數(shù)據(jù)正在努力加載..."  

  32.             });  

  33.             //定義圖表options  

  34.             var options = {  

  35.                 title : {  

  36.                     text : "未來一周氣溫變化",  

  37.                     subtext : "純屬虛構(gòu)",  

  38.                     sublink : "http://www.baidu.com"  

  39.                 },  

  40.                 tooltip : {  

  41.                     trigger : 'axis'  

  42.                 },  

  43.                 legend : {  

  44.                     data : [ "最高氣溫" ]  

  45.                 },  

  46.                 toolbox : {  

  47.                     show : true,  

  48.                     feature : {  

  49.                         mark : {  

  50.                             show : true  

  51.                         },  

  52.                         dataView : {  

  53.                             show : true,  

  54.                             readOnly : false  

  55.                         },  

  56.                         magicType : {  

  57.                             show : true,  

  58.                             type : [ 'line', 'bar' ]  

  59.                         },  

  60.                         restore : {  

  61.                             show : true  

  62.                         },  

  63.                         saveAsImage : {  

  64.                             show : true  

  65.                         }  

  66.                     }  

  67.                 },  

  68.                 calculable : true,  

  69.                 xAxis : [ {  

  70.                     type : 'category',  

  71.                     boundaryGap : false,  

  72.                     data : [ '1', '2', '3', '4', '5', '6', '7' ]  

  73.                 } ],  

  74.                 yAxis : [ {  

  75.                     type : 'value',  

  76.                     axisLabel : {  

  77.                         formatter : '{value} °C'  

  78.                     },  

  79.                     splitArea : {  

  80.                         show : true  

  81.                     }  

  82.                 } ],  

  83.                 grid : {  

  84.                     width : '90%'  

  85.                 },  

  86.                 series : [ {  

  87.                     name : '最高氣溫',  

  88.                     type : 'line',  

  89.                     data : [ 11, 22, 33, 44, 55, 33, 44 ],//必須是Integer類型的,String計算平均值會出錯  

  90.                     markPoint : {  

  91.                         data : [ {  

  92.                             type : 'max',  

  93.                             name : '最大值'  

  94.                         }, {  

  95.                             type : 'min',  

  96.                             name : '最小值'  

  97.                         } ]  

  98.                     },  

  99.                     markLine : {  

  100.                         data : [ {  

  101.                             type : 'average',  

  102.                             name : '平均值'  

  103.                         } ]  

  104.                     }  

  105.                 } ]  

  106.             };  

  107.             myChart.setOption(options); //先把可選項(xiàng)注入myChart中  

  108.             myChart.hideLoading();  

  109.             getChartData();//aja后臺交互   

  110.         }  

  111.     </script>  

  112.     <script type="text/javascript">  

  113.         function getChartData() {  

  114.             //獲得圖表的options對象  

  115.             var options = myChart.getOption();  

  116.             //通過Ajax獲取數(shù)據(jù)  

  117.             $.ajax({  

  118.                 type : "post",  

  119.                 async : false, //同步執(zhí)行  

  120.                 url : "${pageContext.request.contextPath}/echarts/line_data",  

  121.                 data : {},  

  122.                 dataType : "json", //返回數(shù)據(jù)形式為json  

  123.                 success : function(result) {  

  124.                     if (result) {  

  125.                         options.legend.data = result.legend;  

  126.                         options.xAxis[0].data = result.category;  

  127.                         options.series[0].data = result.series[0].data;  

  128.                         myChart.hideLoading();  

  129.                         myChart.setOption(options);  

  130.                     }  

  131.                 },  

  132.                 error : function(errorMsg) {  

  133.                     alert("不好意思,,大爺,圖表請求數(shù)據(jù)失敗啦!");  

  134.                     myChart.hideLoading();  

  135.                 }  

  136.             });  

  137.         }  

  138.     </script>  

  139. </body>  

  140. </html>  



controller


  1. package com.ffcs.wlan.controller;  

  2. import java.util.ArrayList;  

  3. import java.util.Arrays;  

  4. import java.util.List;  

  5. import org.slf4j.Logger;  

  6. import org.slf4j.LoggerFactory;  

  7. import org.springframework.stereotype.Controller;  

  8. import org.springframework.web.bind.annotation.RequestMapping;  

  9. import org.springframework.web.bind.annotation.ResponseBody;  

  10. import com.ffcs.wlan.model.EchartData;  

  11. import com.ffcs.wlan.model.Series;  

  12. @Controller  

  13. @RequestMapping("/echarts")  

  14. public class EntityController {  

  15.     private static final Logger logger = LoggerFactory.getLogger(EntityController.class);  

  16.     @RequestMapping("/line_data")  

  17.     @ResponseBody  

  18.     public EchartData lineData() {  

  19.         logger.info("lineData....");  

  20.         List<String> legend = new ArrayList<String>(Arrays.asList(new String[]{"最高氣溫"}));//數(shù)據(jù)分組  

  21.         List<String> category = new ArrayList<String>(Arrays.asList(new String []{"周一","周二","周三","周四","周五","周六","周日"}));//橫坐標(biāo)  

  22.         List<Series> series = new ArrayList<Series>();//縱坐標(biāo)  

  23.         series.add(new Series("最高氣溫", "line",   

  24.                         new ArrayList<Integer>(Arrays.asList(  

  25.                                 21,23,28,26,21,33,44))));  

  26.         EchartData data=new EchartData(legend, category, series);  

  27.         return data;  

  28.     }  

  29.     @RequestMapping("/line_page")  

  30.     public String linePage() {  

  31.         logger.info("linePage....");  

  32.         return "report/line";  

  33.     }  

  34. }  


Echarts 類


  1. package com.ffcs.wlan.model;  

  2. import java.util.ArrayList;  

  3. import java.util.List;  

  4. public class EchartData {  

  5.     public List<String> legend = new ArrayList<String>();//數(shù)據(jù)分組  

  6.     public List<String> category = new ArrayList<String>();//橫坐標(biāo)  

  7.     public List<Series> series = new ArrayList<Series>();//縱坐標(biāo)  

  8.     public EchartData(List<String> legendList, List<String> categoryList, List<Series> seriesList) {  

  9.         super();  

  10.         this.legend = legendList;  

  11.         this.category = categoryList;  

  12.         this.series = seriesList;  

  13.     }  

  14. }  


Series 類


  1. package com.ffcs.wlan.model;  

  2. import java.util.List;  

  3. public class Series  {  

  4.     public String name;  

  5.     public String type;  

  6.     public List<Integer> data;//這里要用int 不能用String 不然前臺顯示不正常(特別是在做數(shù)學(xué)運(yùn)算的時候)  

  7.     public Series( String name, String type, List<Integer> data) {  

  8.         super();  

  9.         this.name = name;  

  10.         this.type = type;  

  11.         this.data = data;  

  12.     }  

  13. }  



    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn),。請注意甄別內(nèi)容中的聯(lián)系方式,、誘導(dǎo)購買等信息,謹(jǐn)防詐騙,。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,,請點(diǎn)擊一鍵舉報,。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多