Exporting Charts as PDF or Images > Client-side export > Setting JavaScript callback |
When using FusionCharts Export component, you can configure the component to invoke a callback JavaScript method, when the chart has been saved by user. This is useful for tracking whether the exported charts have been saved by your user. By default, the invoked function name is FC_Exported(objRtn). You can, however, call a different function as well by specifying the following in your chart XML: <chart .. exportCallback='myCallBackFunction' ...> And you then need to define this function in your JavaScript code. However, if you do not define any call back function in your XML, the default callback function FC_Exported is invoked. In either case, an object is passed to the function as FC_Exported(objRtn) or myCallBackFunction(objRtn), which contains the following parameters (returned from Export Component):
Let's quickly see an example code where a callback function has been implemented. In this example, once the user has saved the exported chart on his disk (after clicking the Save button for the same), we just show it in a JavaScript alert. |
<html> <body bgcolor="#ffffff"> <div id="fcexpDiv" align="center">FusionCharts Export Handler Component</div> </body> |
FC_ExportReady event |
At times, you might want to track the event when the chart has finished its capture phase and has passed the data to export component, but user has not saved the image/PDF on his disk. Between initiation of chart export and till the time FC_ExportReady event is raised, you might show a waiting message/alert to the user that the chart is in processing stage. The syntax of event is FC_ExportReady(DOMId). You can use DOMId (string) as the identifier for each chart to check which chart has finished processing. The following code explains its usage: |
<script type="text/javascript"> //This event is raised when the chart has finished capture phase and passed the data to //Export Component for further processing function FC_ExportReady(DOMId){ alert("The chart with DOM ID as " + DOMId + " has finished capture mode. It's now ready to be downloaded"); } </script> |