1. 概述
1.1 問題描述
一般情況下我們将網頁中的一部分嵌入了一張 FR 做的報表,圖表數據比較密集,我們希望能夠進行縮放,從而更加清楚地查看報表,就需要定義報表的縮放。
縮放可放大和縮小報表頁面,Web 頁面調用,效果如下圖:
注:也可以直接在模板工具欄中添加縮放按鈕。
1.2 實現思路
通過 FR 内置的 JS 函數 contentPane.scale('+') 可以對報表頁面進行放大,通過 contentPane.scale('-') 可以對報表頁面進行縮小,再利用contentPane.zoom可以獲取到當前報表顯示的比例,進而實現可自定義的頁面放大及縮小。
2. 操作步驟
2.1 設置模板
我們使用模板FR_HOME%\webapps\webroot\WEB-INF\reportlets\doc\Advanced\Chart\Bubble.cpt 來作爲内嵌 iframe。
2.2 設置 HTML 頁面
新建一個 HTML 文件,首先定義 JavaScript 代碼觸發放大縮小的功能,代碼如下:
<script type="text/javascript">
function afterload(){
document.getElementById('reportFrame').contentWindow.contentPane.scale('-');
fuzhi();
}
function afterload2(){
document.getElementById('reportFrame').contentWindow.contentPane.scale('+');
fuzhi();
}
function fuzhi()
{
var contentPane = document.getElementById("reportFrame").contentWindow.contentPane;
var zoom = contentPane.zoom * 100 +"%";
document.getElementById("zoom").value = zoom; //将新的顯示百分比賦給zoom文本框
}
</script>
其次在 body 裏面直接調用 JS 裏面定義好的方法,代碼如下:
<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>
完整代碼如下
<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.contentPane.scale('-');
fuzhi();
}
function afterload2(){
document.getElementById('reportFrame').contentWindow.contentPane.scale('+');
fuzhi();
}
function fuzhi()
{
var contentPane = document.getElementById("reportFrame").contentWindow.contentPane;
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/Advanced/Chart/Bubble.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.3 保存預覽
啓動設計器,在浏覽器輸入:http://localhost:8075/webroot/help/page_demo/zoom.html,效果如下圖: