darcy

Trouble exporting chart to PDF after changing caption attribute

Recommended Posts

I have a project that shows graphs of various bits of information. I've been able to create PDF's of the rendered graphs but have recently been asked to show additional information only when the graph is exported as a PDF. I've chosen to populate the caption attribute of the XML to show the additional information but haven't been able to export the PDF once I've changed the XML.

Here's the code I'm doing in the javascript of the page:

// Get the current chart information
var chartObj = getChartFromId('<%=CallGraph1.ClientID%>_FC');
var chartXML = chartObj.getXML();
// add a caption 
var newXML = chartXML.substr(0, chartXML.indexOf("animation") - 1);
newXML = newXML.concat(captionString); // captionString is defined and created above 
newXML = newXML.concat(chartXML.substr(chartXML.indexOf("animation")-1));
// update the current chart information to include the new caption
chartObj.setDataXML(newXML);
// chartObj.render('<%=CallGraph1.ClientID%>_FCDiv'); /* note that this fails as no method is found */
// Export the chart to PDF
if (chartObj.hasRendered()) /* at this point the graph is NOT in rendered state so the exportChart method is never called */
chartObj.exportChart();

My biggest issue is that once I modify the chart it's no longer "rendered" so won't export to PDF. I haven't found a way to render the chart again once I modify it.

Any suggestions?

Share this post


Link to post
Share on other sites

Hi,

 

 

 

Please make sure that this line inside the condition is getting executed i.e. chartObj.hasRendered() evaluates to true

 

 

 

chartObj.exportChart();

 

 

 

 

 

Also please make sure that export related XML attributes are retained while you update the XML.

Share this post


Link to post
Share on other sites

Thanks for the response!

The part that fails is here:

if (chartObj.hasRendered()) chartObj.exportChart();

The call to hasRendered() returns false so the next line (exportChart) never gets called.

As for the chart attributes, I'm first pulling the XML from the graph then adding a caption. Here's the XML before and after I've added my caption property (note that the data has been removed from this post).

Before:

<chart showFCMenuItem="0" animation="1" showLabels="1" rotateLabels="0" showYAxisValues="1" formatNumberScale="0" decimals="2" exportShowMenuItem="1" exportEnabled="1" exportAtClient="0" exportHandler="/Exporting/FCExporter.aspx" exportDialogMessage="Preparing graph:" exportFormats="PDF=Export as PDF" exportAction="download" exportFileName="Log" bgAlpha="0" showLegend="1" legendPosition="RIGHT" showBorder="1" defaultAnimation="1" showValues="0">

After:

<chart showFCMenuItem="0" caption="Date Range: 5/25/2010 to 5/26/2010" animation="1" showLabels="1" rotateLabels="0" showYAxisValues="1" formatNumberScale="0" decimals="2" exportShowMenuItem="1" exportEnabled="1" exportAtClient="0" exportHandler="/Exporting/FCExporter.aspx" exportDialogMessage="Preparing graph:" exportFormats="PDF=Export as PDF" exportAction="download" exportFileName="Log" bgAlpha="0" showLegend="1" legendPosition="RIGHT" showBorder="1" defaultAnimation="1" showValues="0">

The two appear the same except for the addition of the Date Range caption property.

So it looks like modifying the chart means I need to render it again? Any suggestions on how I do that?

Thanks again for any help you can offer.

 

Share this post


Link to post
Share on other sites

First... when you do setDataXML on the chart the second time, you need not render it again.

 

 

 

Hence, the line

// chartObj.render('<%=CallGraph1.ClientID%>_FCDiv'); /* note that this fails as no method is found */

is not necessary.

 

 

 

 

 

Now, after you set the XML of the chart (the 2nd time), it will take some time to process the new XML and render it and you are calling export method during that time. This is causing your code to break.

 

 

 

The solution is pretty simple: after doing setDataXML, execute the export function after a 2000ms timeout (or a recursive timeout)

 

 

 

So in your code, replace the last if-block with:

 

setTimeout(function () { chartObj.exportChart(); }, 2000);

Share this post


Link to post
Share on other sites
Guest Basundhara Ghosal

Hi,

You are welcome.

Glad that your issue is resolved.

Happy FusionCharting. :)

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