java學(xué)習(xí)

          java學(xué)習(xí)

           

          extjs和highcharts整合顯示數(shù)據(jù)曲線和打印圖片

          Ext.namespace('Ext.ux');

          Ext.ux.WaterRealtimeDisplayPanel = function(treeNode, panelId, config) {
              this.treeNode = treeNode;
              this.panelId = panelId;
              var series=[{"name":"實(shí)時數(shù)據(jù)顯示","data":[]}];
              
              var temhum = new Ext.form.ComboBox({
                  name : 'temhunm',
                  fieldLabel : '狀態(tài)',
                  allowBlank : false,
                  blankText : '請選擇溫濕度',
                  editable : false,
                  triggerAction : 'all',//all表示把下拉框列表框的列表值全部顯示出來
                  store : new Ext.data.ArrayStore({
                      fields : [ 'name', 'value' ],
                      data : [ [ '溫度', '1' ], [ '濕度', '2' ] ]
                  }),
                  mode : 'local',
                  displayField : 'name',
                  valueField : 'value',
                  width : 60
              });
              var storeProvince = new Ext.data.JsonStore({   
                  autoLoad:true,   
                  url : path+"/wenshi/getnode",   
                  root : "options",   
                  fields : [ {   
                      name : 'name'  
                  }]
              });
              var nodeCtl = new Ext.form.ComboBox({
                  fieldLabel : '節(jié)點(diǎn)',
                  allowBlank : false,
                  blankText : '請選擇節(jié)點(diǎn)',
                  editable : false,
                  triggerAction : 'all',
                  store : storeProvince,
                  mode : 'local',
                  displayField : 'name',
                  valueField : 'name',
                  width : 140
              });
              var stTime = new Ext.form.DateField({
                          fieldLabel    : '選擇時間',
                          allowBlank    : false,
                          emptyText    : '請選擇開始日期',
                          editable    : false,
                          format        : 'Y-m-d',
                          maxValue    : new Date(),
                          width        : 130
                      });
              var data = [
                  ['y','年'],
                  ['m','月'],
                  ['d','日']
                //  ['w','周']
              ];

              var store = new Ext.data.SimpleStore({
                  fields: ['value', 'text'],
                  data: data
              });
              var combo = new Ext.form.ComboBox({
                  store: store,
                  fieldLabel:"請選擇時間對應(yīng)的類型",
                  emptyText: '請選擇篩選類型',
                  mode: 'local',
                  triggerAction : 'all',
                  valueField: 'value',
                  displayField: 'text'
              });
              Ext.ux.WaterRealtimeDisplayPanel.superclass.constructor.call(this, {
                          id : this.panelId,
                          title : this.treeNode.text,
                          closable : true,
                          autoScroll : true,
                          height : 400,
                          items:[
                              {  
                          layout:'column',  
                          border:false,  
                          items:[{  
                          //columnWidth: .25 ,  
                          layout:'form',  
                          border:false,  
                          labelAlign:'right',  
                          width : 200,  
                          labelWidth:40,  
                          items:[
          temhum,  nodeCtl]  
                          }
                          ,{  
                              layout:'form',  
                              width : 200,  
                              labelWidth:60,  
                              border:false,  
                              labelAlign:'left',  
                              items:[stTime]  
                          },//combo
                          combo
                          ,
                          {    
                              layout:'form',  
                              border:false,  
                              scope:this,  
                              items:[{  
                                  xtype:'button',  
                                  border:false,
                                  width:70,
                                  style:"margin-left:10px",
                                  text:'查詢',  
                                  scope:this,  
                                  handler:function(){
                                      
                                      // 獲取表單對象  
                                      var _params_ = this.getForm().getValues(false);    
                                      var nodeid = nodeCtl.getValue();//獲取節(jié)點(diǎn)id
                                      var checktype=combo.getValue();//選擇的篩選類型
                                      var checktime=stTime.getValue();//獲取時間的值
                                      var th = temhum.getValue();
                                      if (th == undefined || th == ''){
                                          Ext.Msg.alert("提示","節(jié)點(diǎn)不能為空");
                                          return;
                                      }
                                      if (nodeid == undefined || nodeid == ''){
                                          Ext.Msg.alert("提示","節(jié)點(diǎn)不能為空");
                                          return;
                                      }
                                      if(!stTime.isValid()){
                                          Ext.Msg.alert('信息', '時間為必選項(xiàng)');    
                                          return;
                                      }                          
                                      if (checktype == undefined || checktype == ''){
                                          Ext.Msg.alert("提示","篩選類型不能為空");
                                          return;
                                      }
                                      // 獲得統(tǒng)計(jì)【就是顯示的那個圖】 配置文件對象  
                                      var _op_ = this.getOptions();
                                      
                                      //首先從后臺獲得x軸上值
                                      var categories=_op_.xAxis.categories;
                                      categories=[];
                                      $.ajax({  
                                              type:"POST",  // 提交方式  
                                              url:path+'/wenshi/collectHositoryDataName', // 提交地址         
                                              dataType:"json", // 解釋格式  
                                              data:{"nodeid":nodeid,"checktime":checktime.format('Y-m-d'),"checktype":checktype,"th":th},     // 請求參數(shù)  
                                              success:function(iJson){  
                                                  var results = eval(iJson); // 轉(zhuǎn)換成 JSON 數(shù)據(jù)  
                                             var r = results[0].data;
                                           for(var i=0;i<r.length;i++){
                                               categories.push(r[i]);
                                           }
                                              
                                                  _op_.xAxis.categories=categories;
                                               },  
                                              error:function(){  
                                                  Ext.Msg.alert('系統(tǒng)操作','網(wǎng)絡(luò)不通暢或數(shù)據(jù)格式不對!');  
                                              }  
                                      });
                                     
                                      // 獲得統(tǒng)計(jì) 對象的 數(shù)據(jù)
                                      var _series_ = _op_.series;                             
                                      // 清空 統(tǒng)計(jì) 對象的 數(shù)據(jù) 重新加載                              
                                      _series_ = [] ;  
                                      // 創(chuàng)建一個統(tǒng)計(jì) 對象胡方法   
                                      var _createChart_ = function (obj){new Highcharts.Chart(obj);};  
                                      // 向后臺發(fā)送請求   
                                  var d = new Ext.util.DelayedTask(function(){  
                                       $.ajax({  
                                              type:"POST",  // 提交方式  
                                              url:path+'/wenshi/collectHositoryData', // 提交地址         
                                              dataType:"json", // 解釋格式  
                                              data:{"nodeid":nodeid,"checktime":checktime.format('Y-m-d'),"checktype":checktype,"th":th},     // 請求參數(shù)  
                                              success:function(iJson){  
                                                  var results = eval(iJson); // 轉(zhuǎn)換成 JSON 數(shù)據(jù)  
                                                  for(var i =0 ; i < results.length;i++){  // 解釋和裝載數(shù)據(jù)   
                                                      _series_.push({name:results[i].name,data:results[i].data});  
                                                  }  
                                                  _op_.series = _series_; // 賦值   
                                                  _createChart_(_op_);  // 重新創(chuàng)建一個統(tǒng)計(jì)  
                                               },  
                                              error:function(){  
                                                  Ext.Msg.alert('系統(tǒng)操作','網(wǎng)絡(luò)不通暢或數(shù)據(jù)格式不對!');  
                                              }  
                                      });
                                   });  
                                   d.delay(1000);
                                  }  
                              }]  
                          }]  
                      },
                      {  
                          xtype:'panel',  // 創(chuàng)建  Highcharts  所依賴的 div   
                          html:'<div id="'+"test"+'" style="width:1000px; height: 500px; margin: 0 auto"></div>'  
                      }
                              ],
                          listeners : {
                              activate : function(p) {
                                    var obj=this.getOptions();
                                    obj.series=series;
                                    var chart =new Highcharts.Chart(obj);
                              }
                          },
                          getOptions:function(){
                              return     {
                                              chart : {
                                                  renderTo :"test",
                                                    type: 'spline'
                                              },
                                              lang : {
                                                  exportButtonTitle : '導(dǎo)出圖表',
                                                  printButtonTitle : '打印報表'
                                              },
                                              title : {
                                                  text : '節(jié)點(diǎn)歷史參數(shù)曲線圖'
                                              },
                                              xAxis : {
                                                  title : {
                                                      text : '采集時間'
                                                  }
                                                 ,
                                                  //categories : ['1秒', '2秒','3秒']//設(shè)置x軸上分類名稱
                                              },
                                              yAxis : {
                                                  title : {
                                                      text : '節(jié)點(diǎn)參數(shù)值'
                                                  },
                                                  plotLines: [{  
                                                        value: 0,  
                                                        width: 1,  
                                                        color: '#808080'  
                                                       }]
                                              },
                                              tooltip: {  
                                                          //enabled: false,  //是否顯示提示框
                                                          formatter: function() {  
                                                                  return "時間:"+this.x +'<br/>'+"參數(shù)值:"+ this.y;
                                                          }  
                                                    }
                                              //,
          //                                   series : [{
          //                                                name : '實(shí)時數(shù)據(jù)顯示',
          //                                                data : [141, 100, 4]
          //                                            }]
                                          };
                          }
                      });
          };
          Ext.extend(Ext.ux.WaterRealtimeDisplayPanel, Ext.FormPanel, {
          });
          Ext.reg('ljsStudentTuPanel', Ext.ux.WaterRealtimeDisplayPanel);


          后臺導(dǎo)出圖片的方法是:
          public class ImageController extends Controller{

              public void index(){
                  
                  String type = getPara("type");
                  String svg =getPara("svg");
                  String filename = getPara("filename");
                  ServletOutputStream out1 =  null;
                  try {
                      filename = filename==null?"chart":filename;
                       out1 = getResponse().getOutputStream();
                      if (null != type && null != svg) {
                          svg = svg.replaceAll(":rect", "rect");
                          String ext = "";
                          Transcoder t = null;
                          if (type.equals("image/png")) {
                              ext = "png";
                              t = new PNGTranscoder();
                          } else if (type.equals("image/jpeg")) {
                              ext = "jpg";
                              t = new JPEGTranscoder();
                          } else if(type.equals("image/svg+xml")) {
                                ext = "svg";
                          }else if(type.equals("application/pdf")){
                              t = new PDFTranscoder();
                              ext = "pdf";
                          }
                              
                          getResponse().addHeader("Content-Disposition", "attachment; filename="+ filename + "."+ext);
                          getResponse().addHeader("Content-Type", type);
                          
                          if (null != t) {
                              TranscoderInput input = new TranscoderInput(new StringReader(svg));
                              TranscoderOutput output = new TranscoderOutput(out1);                    
                              try {
                                  t.transcode(input, output);
                              } catch (TranscoderException e) {
                                  out1.print("Problem transcoding stream. See the web logs for more details.");
                                  e.printStackTrace();
                              }
                          } else if (ext.equals("svg")) {
                              OutputStreamWriter writer = new OutputStreamWriter(out1, "UTF-8");
                              writer.append(svg);
                              writer.flush();
                              writer.close();
                          } else
                              out1.print("Invalid type: " + type);
                      } else {
                          //getResponse().addHeader("Content-Type", "text/html");
                         // out.println("Usage:\n\tParameter [svg]: The DOM Element to be converted." +
                         //         "\n\tParameter [type]: The destination MIME type for the elment to be transcoded.");
                      }
                      
                  } catch (Exception e) {
                      e.printStackTrace();
                  }finally{
                      try {
                          out1.flush();
                          getResponse().flushBuffer();
                          out1.close();
                          
                      } catch (Exception e2) {
                      
                      }
                      
                  }
                  
                  renderNull();//不跳轉(zhuǎn)
                  
                  

                  }
          }

          posted on 2013-03-08 17:01 楊軍威 閱讀(3424) 評論(2)  編輯  收藏

          評論

          # re: extjs和highcharts整合顯示數(shù)據(jù)曲線和打印圖片 2013-05-10 10:47 lln

          沒看到打印是那一塊啊  回復(fù)  更多評論   

          # re: extjs和highcharts整合顯示數(shù)據(jù)曲線和打印圖片 2013-05-27 17:34 楊軍威

          @lln
          @lln
          @lln
          現(xiàn)在有導(dǎo)出圖片的方法了  回復(fù)  更多評論   


          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 莱阳市| 绥江县| 彭山县| 翁牛特旗| 汉寿县| 清远市| 新蔡县| 万全县| 东方市| 林州市| 连州市| 宣威市| 石家庄市| 政和县| 利川市| 洛隆县| 同德县| 尖扎县| 中超| 横峰县| 罗定市| 股票| 上虞市| 七台河市| 中超| 富宁县| 铅山县| 曲沃县| 健康| 思南县| 惠州市| 本溪市| 平南县| 南靖县| 礼泉县| 集贤县| 咸丰县| 天全县| 抚宁县| 包头市| 团风县|