1 所需/涉及文件

文件类型

文件名

功能

js

FusionCharts.js

基础库

FusionChartsExportComponent.js

导出功能组件

index.js

自定义

Jar

fcexporter.jar

基础jar

fcexporter-jdk15.jar

Servlet扩展

jsp

FCExporter.jsp

主要导出功能

FCExporterError.jsp

出错页面

index.jsp

自定义

FCExporter_IMG.jsp

FCExporter_PDF.jsp

配置文件

fusioncharts_export.properties

基本属性,目录等的配置

Web.xml

Servlet的配置

Swf文件

FCExporter.swf

导出格式选择控件

Pie3D.swf

根据现实需要

2 目录结构 2.1 开发目录

clip_image002[1]

2.2 Jar位置

D:\bea_adp\adp\deploy\WEB-INF\lib下

clip_image004[1]

2.3 配置文件

D:\bea_adp\adp\deploy\WEB-INF\classes目录下:

clip_image006[1]

3 配置步骤 3.1 配置servlet

在web.xml里编写如下代码:

<!-- funsioncharts的支持 -->

<servlet>

<display-name>FCExporter</display-name>

<servlet-name>FCExporter</servlet-name>

<servlet-class>com.fusioncharts.exporter.servlet.FCExporter</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>FCExporter</servlet-name>

<url-pattern>/FCExporter</url-pattern>

</servlet-mapping>

3.2 配置文件

#This constant defines the name of the export handler jsp file - DO NOT MODIFY THIS!!!

EXPORTHANDLER=FCExporter_

#Path where the export handler files are located

#Please note that the resource path should be relative to

#FCExporter.jsp file's directory

#By default the path is "Resources/"

RESOURCEPATH=work\\zhd_test\\Resources\\

#Please specify the path to a folder with write permissions relative to web application root

#The exported image/PDF files would be saved here.

SAVEPATH=./work/zhd_test/savefiles/

#This constant HTTP_URI stores the HTTP reference to

#the folder where exported charts will be saved.

#Please enter the HTTP representation of that folder

#in this constant e.g., http://www.yourdomain.com/images/

HTTP_URI=http://localhost:7001/adp/work/zhd_test/savefiles/

#OVERWRITEFILE sets whether the export handler would overwrite an existing file

#the newly created exported file. If it is set to false the export handler would

#not overwrite. In this case if INTELLIGENTFILENAMING is set to true the handler

#would 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

【注】:RESOURCEPATH 配置的是FCExporter_IMG.jsp、FCExporter_PDF.jsp两个文件所在的路径(我的

FCExporter_IMG.jsp、FCExporter_PDF.jsp文件放在了WebRoot下面的Resources文件夹里了),

SAVEPATH 配置的是导出图片保存路径(需要在工程里事先建好),HTTP_URI 配置的是保存图片的服务器的绝对路径。(其他的属性不要变,否则会出问题)

3.3 关键代码

见Demo文件中的注释

3.4 效果图

clip_image008

点击导出后,提示“正在导出”

clip_image010

下方显示可供用户选择的按钮。

clip_image012

点击“Save”后:弹出保存提示框,选择保存目录,点击保存后即可。

clip_image014

4 遇到问题及解决过程

目录问题

在properties配置文件中,resources路径要用work\\zhd_test\\Resources\\的方式来配置

系统目录与业界通用目录有区别,经过跟踪代码后解决。

路径核对

注意jsp及js中如果有带有目录的,如引用swf文件等内容,要核对路径

犯过多次错误,认真读一读jsp和js即可。

包冲突

getChartFromId这个方法使用没问题,网上的文档有时候会用var chart = FusionCharts("chart1Id");这种方式来处理,却会报找不到对象错误,很奇怪

核对多个网上载下来的Demo后,找到当前环境可用的方法。

5 参考文献

http://shihuan830619.javaeye.com/blog/833813

http://blog.sina.com.cn/s/blog_4f925fc30100o28l.html

http://forum.fusioncharts.com