1. 概述
1.1 問題描述
一般情況下我們將網頁中的一部分嵌入了一張 FR 做的報表,圖表資料比較密集,我們希望能夠進行縮放,進而更加清楚地查看報表,就需要定義報表的縮放。
縮放可放大和縮減報表頁面,Web 頁面呼叫,效果如下圖所示:
注:也可以直接在範本工具欄中新增縮放按鈕。
1.2 實現思路
透過 FR 內建 JS 函式 _g().scale('+') 可以對報表頁面進行放大,透過_g().scale('-') 可以對報表頁面進行縮減,再利用contentPane.zoom可以獲取到當前報表顯示的比例,進而實現可自訂的頁面放大及縮減。
2. 操作步驟
2.1 範本準備
我們使用範本%FR_HOME%\webapps\webroot\WEB-INF\reportlets\doc\Primary\BasicChart\力學氣泡圖.cpt來作為內嵌 iframe。
2.2 建立 HTML 檔案
1)建立zoom.html檔案,內容如下:
點選下載檔案:zoom.zip
<html>
<head>
<title>自訂縮放按鈕</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<script type="text/javascript">
function afterload(){
document.getElementById('reportFrame').contentWindow._g().scale('-');
fuzhi();
}
function afterload2(){
document.getElementById('reportFrame').contentWindow._g().scale('+');
fuzhi();
}
function fuzhi()
{
var contentPane = document.getElementById("reportFrame").contentWindow._g();
var zoom = contentPane.zoom * 100 +"%";
document.getElementById("zoom").value = zoom; //將新的顯示百分比賦給 zoom 正文框
}
</script>
<body>
<iframe id="reportFrame" width="900" height="500" src="/webroot/decision/view/report?viewlet=/doc/Primary/BasicChart/力學氣泡圖.cpt"></iframe>
<body onload="fuzhi()">
<div id="toolbar">
<input type="button" onclick="afterload();" value="-"></input>
<input id="zoom" type="text" readonly="true" style="width: 80px">
<input type="button" onclick="afterload2();" value="+"></input>
</div>
</body>
</html>
2)將 zoom.html 放置到 %FR_HOME%\webapps\webroot\help\page_demo 路徑下,如下圖所示:
2.3 效果預覽
啟動設計器,在瀏覽器輸入:http://localhost:8075/webroot/help/page_demo/zoom.html,效果如下圖所示: