Configuring Fusion Charts Exporting To Pdf With Springs

Recommended Posts



I have problem configuring Fusion charts for exporting PDF/images into springs framework.


My big doubt was i followed below steps to set up the environment

which was specified in ReadMe which came with FusionCharts_Evaluation


FusionCharts Server-side Export Handler - J2EE



For exporting the chart as image/pdf at server side using JSP, the following library files are required on your server:


1. fcexporter.jar (contains all the dependency classes)

2. fcexporthandler.jar (contains the export handler servlet and resources)

3. /classes/ (configuration file)





Step1: Copy the neccessary files

Please place the export jars fcexporter.jar and fcexporthandler.jar in WEB-INF/lib and in WEB-INF/classes folder.


FusionCharts Exporter has been tested with JDK 1.5.

Note that the FusionCharts Exporter jars for jdk1.4.2 is also available in ExportHandlers/JDK1.4 folder


Step2: Configure web.xml

Add the following servlet mapping in your application's web.xml












Please modify the url-pattern as per your application needs.


Specify the xml attribute exportHandler='FCExporter' assuming that the jsp rendering the chart is present in /JSP/ExportExample folder.



Configuration of save folder for server-side save


This is to be done in file. Make sure that the folder path that you specify

has write permissions to it.



I am facing problem while configuring <url-pattern>/JSP/ExportExample/FCExporter</url-pattern>

As we are using Springs framework navigation to different pages were done via ModelView mapper that mean we use MVC .


For generating the chart I use the following method

public ModelViewMapper showBarchartReport(final HttpServletRequest request,


final HttpServletResponse response)

throws IOException {"ReportsHandler:showBarchartReport:Enter");

// added for dynamic levels

int inputHid1 = Integer.parseInt(request.getParameter("InputHid"));

String inputHid = inputHid1 + "";

inputHid = inputHid.trim();

String startDate = "";

String endDate = "";

String sztimestamp = ReportsHandler.getServerTime();

startDate = (String) request.getParameter("startDate");

endDate = (String) request.getParameter("endDate");


try {

if (inputHid != null) {


ChartReportsImpl fimpl = new ChartReportsImpl();

String strxml = fimpl.generateChartReport(startDate,



XmlElement xmlElement = null;

xmlElement = XmlElement.createXmlElement(strxml);

xmlElement.setAttribute("caption"," Application Name: "+szApplicationName+

" Report Created On:- "+sztimestamp);

int count = xmlElement.getCountByXPath("//set");

int i = 0;

for (int j = 1; j <= count; j++) {

String value = null;

value = xmlElement.getElementByXPath(

"//set[" + j + "]").getAttribute("value");

if (value.equals("")) {



//"Val---" + i);




if (i == count) {

//"counting for null--");

request.setAttribute("count", NO_RECORDS_FOUND);

return new ModelViewMapper(RETURN_FAILURE);


} else {

String path = (String) request.getRealPath("/");

FileWriter fw = new FileWriter(

new File(path + "/modular/swf/data/Column3D.xml"));

strxml = xmlElement.getXmlString();

//added by sandeep

strxml = strxml.replace("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>", "");

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

DocumentBuilder db = dbf.newDocumentBuilder();

InputSource is = new InputSource();

is.setCharacterStream(new StringReader(strxml));

Document doc = db.parse(is);

NodeList nodeList;

Element element;

String label;

nodeList = doc.getElementsByTagName("set");

for(int j=0; j< nodeList.getLength() ; j++)


element = (Element)nodeList.item(j);

label = element.getAttribute("label");

if(label.equalsIgnoreCase("RESPONSE RECEIVED"))





Element root = doc.getDocumentElement();


TransformerFactory transfac = TransformerFactory.newInstance();

Transformer trans = transfac.newTransformer();

StringWriter sw = new StringWriter();

StreamResult result = new StreamResult(sw);

DOMSource source = new DOMSource(doc);

trans.transform(source, result);

strxml = sw.toString();"**************** Bar chart XML test : **************"+strxml);

//end of sandeep code.





String szUserId = (String)request.getParameter("userid");

InputStream inputStream =


Properties properties = new Properties();


String path_attachments = properties.getProperty("attachment_location");

String path_zip = properties.getProperty("attachment_location_zip");

//String path_zip1=path_zip.substring(23,58);

if(szUserId.length() > 0){


ReportsImpl reportsimpl = new ReportsImpl();

reportsimpl.sendEmail(szUserId, path_zip);

/*File attachments = new File(path_attachments);

String[] children = attachments.list();

boolean status = false;

for (int f=0; f<children.length; f++) {

status = new File(attachments, children[f]).delete();


status = attachments.delete();


File zip = new File(path_zip);

status = zip.delete();





} else {;


} catch (Exception e) {

LOGGER.error(" Exception in showBarchartReport : " , e);



request.setAttribute("reportstatus", RETURN_SUCCESS);"ReportsHandler:showBarchartReport:Exit");

return new ModelViewMapper(RETURN_SUCCESS);


which would be present in one of java handler and when it returns status either success/ failure it is directed to some jsp pages my big quest is for this url-pattern what would be the rendering jsp to be placed in url_pattern? as when i specify the jsp which actually renders the chart i'm not able to export the report instead it pops up the window which was attached and when i try to open it i get the following message displayed instead of chart


statusMessage= Insufficient data. Width/height not provided.Background Color not specified. Taking White (FFFFFF) as default background color.






Please help me out with this ASAP.


Thanks in advance,






Share this post

Link to post
Share on other sites

Hi Neeraja,


Let me try to understand the problem first.


1. I understand that you have some xml document generation code. When this xml is provided to the chart, is the chart getting rendered in the first place?

a. If chart is getting rendered, can you please share the generated xml? This can be obtained by either printing the xml document to a string or by turning on the debugMode in FusionCharts.

b. else, if the chart itself is not rendering, we have to take a look at the view source of the html page.


2. If Chart is getting rendered, but export is not working, then

a. Share the generated xml. Screen-shot / copy-paste of the debug window will also help.

b. tell me the browser and FusionCharts version you are using.


Lets take it from there.


Srividya Sharma :)

Share this post

Link to post
Share on other sites

Hi Srividya,


That was a quick reply and i appriciate it. Sorry couldnt respond back sooner.


Yes, the chart was getting rendered and i am attaching the screenshot and the xml which was generated so that we can move forward.


Waiting for your reply.



Neeraja Meka.





Edited by neeraja

Share this post

Link to post
Share on other sites

Hi Neeraja,


As far as I can see, since you are using the FusionCharts Servlet export handler, you will have to configure the servlet mapping.


Can you tell me which step in the export is failing, what is the output/error you are seeing on the screen?



Srividya Sharma

Share this post

Link to post
Share on other sites

Hi Srividya,


I basically have problem while configuring <servlet-mapping> as i am donot know what is the value to be substituted in <url-pattern> tag I mean to what jsp or servlet page i need to map this servlet (FCExporter) when defining it as a servlet in web.xml file.


Thank you,

Neeraja Meka.



Share this post

Link to post
Share on other sites

Hi Neeraja,


I took a look at your web.xml.


As you had mentioned earlier, the problem seems to be here:







Please note that the value that you provide to exportHandler attribute in the xml should be same as the value provided in the url-pattern.


Only then, the chart will direct to the correct url for handling export.


Please try to invoke the FCExporter servlet directly from the browser and the path that you use there will be the url-pattern or the exportHandler value.


Hope this helps.



Srividya Sharma

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now