FusionCharts Forum: Trouble exporting chart to PDF after changing caption attribute - FusionCharts Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Trouble exporting chart to PDF after changing caption attribute

#1 User is offline   darcy 

  • Forum Newbie
  • Group: Members
  • Posts: 3
  • Joined: 25-May 10

Posted 25 May 2010 - 11:52 AM

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?

0

Other Replies To This Topic

#2 User is offline   Sudipto Choudhury 

  • Supreme Being
  • Group: Administrators
  • Posts: 1919
  • Joined: 19-March 07

Posted 26 May 2010 - 01:37 AM

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.
Regards,

Sudipto Choudhury
FusionCharts Team

Follow us on Twitter

I code, therefore I am.

0

Other Replies To This Topic

#3 User is offline   darcy 

  • Forum Newbie
  • Group: Members
  • Posts: 3
  • Joined: 25-May 10

Posted 26 May 2010 - 11:25 AM

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.

0

Other Replies To This Topic

#4 User is offline   shamasis 

  • Red Flavoured
  • Group: Administrators
  • Posts: 198
  • Joined: 27-October 08
  • LocationKolkata, India

Posted 29 May 2010 - 01:47 PM

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);

0

Other Replies To This Topic

#5 User is offline   darcy 

  • Forum Newbie
  • Group: Members
  • Posts: 3
  • Joined: 25-May 10

Posted 01 June 2010 - 12:43 PM

Thanks Shamasis, the delay was what I was missing.
0

Other Replies To This Topic

#6 User is offline   Basundhara Ghosal 

  • Supreme Being
  • PipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2459
  • Joined: 15-September 09

Posted 02 June 2010 - 12:10 AM

Hi,

You are welcome.

Glad that your issue is resolved.

Happy FusionCharting. :)

Regards,

Basundhara Ghosal

Follow us on Twitter :D
0

Other Replies To This Topic

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic