历史版本18 :自定义缩放按钮 返回文档
编辑时间:
内容长度:图片数:目录数:
修改原因:
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 保存预览
已完成页面请查看%FR_HOME%/webapps/webroot/help/page_demo/zoom.html
启动设计器,在浏览器输入:http://localhost:8075/webroot/help/page_demo/zoom.html,效果如下图: