1,加入jar包(fcexporter.jar ;fcexporthandler.jar ),FCExporter.swf,FusionChartsExportComponent.js
2,拷贝文件FCExporter.php到
WebContent/jsp/ExportHandlers/PHP/FCExporter.php
3,web.xml加入servlet
FCExporter
FCExporter
com.fusioncharts.exporter.servlet.FCExporter
1
FCExporter
/jsp/ExportHandlers/PHP/FCExporter
servlet的url-pattern和上面的文件FCExporter.php路径要一致,去掉后缀.php
4,加入配置文件fusioncharts_export.properties,放在claess路径下(最后到工程的WEB-INF\classes下就对了,里面的属性自己看着改)
#Please specify the path to a folder with write permissions relative to web application root
#SAVEPATH=./tempphoto/
SAVEPATH=./tempExport/
#Please specify the path to a folder with write permissions relative to web application root
#the folder where exported charts will be saved.
#the folder where exported charts will be saved.
#in this constant e.g., http://www.yourdomain.com/images/
#HTTP_URI=http://lsy.helpdesk.citicsinfo.com/tempphoto/
HTTP_URI=http://lsy.helpdesk.citicsinfo.com/tempExport/
#OVERWRITEFILE sets whether the export handler will overwrite an existing file
#the newly created exported file. If it is set to false the export handler will
#not overwrite. In this case if INTELLIGENTFILENAMING is set to true the handler
#will add a suffix to the new file name. The suffix is a randomly generated UUID.
#Additionally, you can add a timestamp or random number as additional prefix.
OVERWRITEFILE=false
INTELLIGENTFILENAMING=true
FILESUFFIXFORMAT=TIMESTAMP
5,在报表的xml数据中药加入几个属性。
' exportEnabled="1" exportAtClient="0" exportAction="save"'
' exportHandler="http://lsy.helpdesk.citicsinfo.com/jsp/ExportHandlers/PHP/FCExporter"'
' exportCallback="myCallBackFunction" '
其中exportHandler="http://lsy.helpdesk.citicsinfo.com/jsp/ExportHandlers/PHP/FCExporter
是你刚才注册的servlet的请求路径,比如http://xxx:8080/aaa,这里我完整的请求就是上面的路径。
例子:
var dataString11 ='\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
';
var dataString12 ='\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
\n\
';
6,页面调用。
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<%
String path = request.getContextPath();
%>
Single Series Column 2D Chart
报表系统--呼入汇总
看着挺多挺乱的。
其实有3点要说明。
这个div是到处时需要用的,方便用户选择导出选项,可以通过showAllowedTypes设置,我直接使用
style="display:none;"隐藏掉了。
还有每导出一张图片,servlet会调一次回调函数
function myCallBackFunction(objRtn){
if (objRtn.statusCode=="1"){
alert("Haha!The chart was successfully saved on server. The file can be accessed from " + objRtn.fileName);
}else{
alert("Oh.The chart could not be saved on server. There was an error. Description : " + objRtn.statusMessage);
}
}
最后就是导出的调用方法和一些参数设置,这样调用
function ffgg(){
var myExportComponent = new FusionChartsExportObject("fcExporter1", "../../../../script/plugin/FusionCharts_Evaluation/Charts/FCExporter.swf");
//myExportComponent.sourceCharts = ['myChartId1','myChartId2','myChartId3'];
myExportComponent.sourceCharts = ['ChartId11','ChartId12'];
myExportComponent.componentAttributes.fullMode='1';
myExportComponent.componentAttributes.saveMode='both';
myExportComponent.componentAttributes.showAllowedTypes='0';
//myExportComponent.componentAttributes.showAllowedTypes='1';
myExportComponent.componentAttributes.width = '350';
myExportComponent.componentAttributes.height = '140';
myExportComponent.componentAttributes.showMessage = '1';
myExportComponent.componentAttributes.message = 'Click on button above to begin export of charts. Then save from here.';
myExportComponent.componentAttributes.defaultExportFileName = 'MyCharts';
myExportComponent.componentAttributes.defaultExportFormat='JPG';// JPG, PNG or PDF
myExportComponent.Render("fcexpDiv");
myExportComponent.BeginExport();
}
具体参数什么意思,查文档吧,里面说的很全很详细。
过程截图:
这样图片就完成了导出。在服务器路径下,你可以找到图片然后进行其他操作。
还有个小问题,就是批量导出时,图片的名字不可设置,是随机生成的,而且多张图片到处时,
没有先后顺序,这样最后生成的图片没法和页面对应,我们拿到这几张图片是无序的,处理起来
没法辨认顺序。我想到一个办法就是每张报表chart都有一个独立的文件夹在服务器下,生成报表图片后,
即使是无序的文件名,我也会让程序按照页面上对应的顺序去服务器下找图片,这样貌似有些麻烦,不失为一个解决途径。