All charts and widgets of FusionCharts for Flex v.1.1 package are provided with a feature that exports the charts and widgets to image or PDF. All you need to call the FCExportChart method and pass proper parameters to it. However, due to security concerns, this function can only be invoked by an interactive-event triggered by the user.
The FCExportChart method is called using the following syntax:
FCExportChart(String format, String fileName)
The fileName parameter denotes the default file name for the exported chart/widget while the format parameter denotes the default format to which the chart/widget will be exported. Both parameters are optional - the default fileName is 'FusionCharts' and default format is 'JPG'. The available formats are "JPG", "PNG" or "PDF".
In the following code (below), the FCExportChart function is called by a click event that occurs when the user clicks a button:
<?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">
<ns1:FCChartData FCData="{chartData}" FCParams="{chartParams}"/>
</ns1:FusionCharts>
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
private var chartData:ArrayCollection=new ArrayCollection([
{ label:'Jan', value:'17400' },
...
{ label:'Jun', value:'27600' }
]);
[Bindable]
private var chartParams:ArrayCollection=new ArrayCollection([
{ caption:'Half Yearly Sales Summary' },
...
{ numberPrefix:'$' }
]);
]]>
</mx:Script>
<mx:Button x="200" y="320" label="Export Chart"
click="myChart.FCExportChart('JPG', 'myChart')" />
</mx:Application>
We begin by assigning an id to our chart called myChart.
<ns1:FusionCharts id="myChart" ... >
This allows us to use FCExportChart function as a method of myChart object. The method will be triggered by a click event of a button.
<mx:Button ... click="myChart.FCExportChart('JPG', 'myChart')" />
Observe that we pass the parameters 'JPG' and 'myChart'into our FCExportChart method. These parameters define the file name for the exported chart/widget and also define the file format to which the chart/widget will be exported.
Upon being invoked the function launches a save dialog box, in which the user can specify the location, where he/she wants to save the exported chart/widget.