历史版本1 :自定义缩放按钮 返回文档
编辑时间: 内容长度:图片数:目录数: 修改原因:

1. 问题描述编辑

一般情况下我们将网页中的一部分潜入了一张FR做的报表,图表数据比较密集,我们希望能够进行缩放,从而更加清楚地查看报表,就需要定义报表的缩放。
缩放可放大和缩小报表页面,Web页面调用,效果如下;
注:也可以直接在模板工具栏中添加缩放按钮。

2. 示例编辑

我们使用模板FR_HOME%\WebReport\WEB-INF\reportlets\doc\Advanced\Chart\Bubble.cpt来作为内嵌iframe。
首先定义javascript代码触发放大缩小的功能,代码如下:
  1. <script type="text/javascript">      
  2.    function afterload(){      
  3.    document.getElementById('reportFrame').contentWindow.contentPane.scale('-');      
  4.    fuzhi();      
  5.    }      
  6.    function afterload2(){      
  7.    document.getElementById('reportFrame').contentWindow.contentPane.scale('+');      
  8.    fuzhi();      
  9.    }      
  10.    function fuzhi()      
  11.    {      
  12.        var contentPane = document.getElementById("reportFrame").contentWindow.contentPane;      
  13.        var zoom = contentPane.zoom * 100 +"%";       
  14.        document.getElementById("zoom").value = zoom;  //将新的显示百分比赋给zoom文本框    
  15.    }      
  16. /script>   
其次在body里面直接调用js里面定义好的方法,代码如下:
  1. <body onload="fuzhi()">    
  2.         <div id="toolbar">    
  3.             <input type="button" onclick="afterload();" value="-"></input>    
  4.             <input id="zoom" type="text" readonly="true" style="width: 80px">    
  5.             <input type="button" onclick="afterload2();" value="+"></input>    
  6.         </div>  
完整代码如下
  1. <html>    
  2.  <head>    
  3.   <title>FineReport Demo</title>    
  4.   <meta http-equiv="Content-Type" content="text/html; charset=GBK" />    
  5.  </head>   
  6. <script type="text/javascript">        
  7.    function afterload(){        
  8.    document.getElementById('reportFrame').contentWindow.contentPane.scale('-');        
  9.    fuzhi();        
  10.    }        
  11.    function afterload2(){        
  12.    document.getElementById('reportFrame').contentWindow.contentPane.scale('+');        
  13.    fuzhi();        
  14.    }        
  15.    function fuzhi()        
  16.    {        
  17.        var contentPane = document.getElementById("reportFrame").contentWindow.contentPane;        
  18.        var zoom = contentPane.zoom * 100 +"%";         
  19.        document.getElementById("zoom").value = zoom;  //将新的显示百分比赋给zoom文本框      
  20.    }        
  21. </script>    
  22.  <body>    
  23.  <iframe id="reportFrame" width="900" height="500" src="/WebReport/ReportServer?reportlet=/doc/Advanced/Chart/Bubble.cpt"></iframe>    
  24. <body onload="fuzhi()">      
  25.         <div id="toolbar">      
  26.             <input type="button" onclick="afterload();" value="-"></input>      
  27.             <input id="zoom" type="text" readonly="true" style="width: 80px">      
  28.             <input type="button" onclick="afterload2();" value="+"></input>      
  29.         </div>   
  30.  </body>    
  31. </html>    
已完成示例请参照%FR_HOME%\WebReport\page_demo\zoom.html

在线查看示例效果请点击zoom.html