FusionCharts for Flex > Exporting as Image/PDF > Callback Function

When the export of charts/widgets to image or PDF is completed, an event named FCExported is triggered.

The FCExported event returns an object of FCEvent type. This object contains three export callback parameters:

  • event.param.success - This parameter returns a Boolean value, which indicates whether the export process was successful or unsuccessful. The event returns a 'false' value, if the export process was interrupted, canceled, or had failed. On the other hand 'true' indicates success of the operation.
  • event.param.fileFormat - This parameter returns a string value, which indicates the format to which the chart/widget was encoded. In case the export operation fails, FCExported will return the default export format.
  • event.param.fileName - This parameter returns a string value, which returns the name of the file to which the exported chart/widget was saved. In case the export operation fails, FCExported will return the default file name.

The following example shows, how to trap the FCExported event. The parameters returned by the event will be displayed in an alert box:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
xmlns:ns1="com.fusioncharts.components.*">

<ns1:FusionCharts id="myChart" x="10" y="10" FCChartType="Column3D"
FCExported="callBack(event)">
<ns1:FCChartData FCData="{chartData}" FCParams="{chartParams}"/>
</ns1:FusionCharts>

<mx:Script>
<![CDATA[
import com.events.FCEvent;
import mx.collections.ArrayCollection;
import mx.controls.Alert;

//Create an object as a data source for chart
[Bindable]
private var chartData:ArrayCollection=new ArrayCollection([
{ label:'Jan', value:'17400' },
...
{ label:'Jun', value:'27600' }
]);

//Create an object as a data source for chart parameters
[Bindable]
private var chartParams:ArrayCollection=new ArrayCollection([
{ caption:'Half Yearly Sales Summary' },
...
{ numberPrefix:'$' }
]);

private function callBack(e:FCEvent):void {
Alert.show(
e.param.success + "\n"
+ e.param.fileFormat + "\n"
+ e.param.fileName);
}


]]>
</mx:Script>

<mx:Button x="200" y="320" label="Export Chart"
click="myChart.FCExportChart('PNG')" />
</mx:Application>

Firstly, we register our callback function callBack with the FCExported event in the FusionCharts tag.

<ns1:FusionCharts ... FCExported="callBack(event)">

Next, we define a callback function, which will return the three parameters through an alert box.

The export operation is initiated by a click event associated with a button.