FusionCharts and Flash > Using External data |
In the previous example we have seen how we can create a chart in Flash 8. In this section, we will modify the code to load chart data from external data source. To make the sample easy we will take a static XML file containing hardcoded data in it. In real-life implementation you can always use other dynamic sources. If you wish to use FusionCharts in your Adobe Flex solutions please read Using Flex or if you wish to use FusionCharts in your Flash CS4/CS4 movies, please have a look at Using Flash CS3/CS4. |
Loading external data |
In this sample we will do the following:
The code shown below works this out : |
#include "com/fusioncharts/includes/LoadingFunctions.as" #include "com/fusioncharts/includes/AppMessages.as" import com.fusioncharts.core.charts.Column2DChart; // Initialize XML object var xmlData:XML = new XML(); // ------------- Define XML Data for the chart -------------- // // Here, we're loading the XML data from an external file. // For a simple head-start we've used a pre-defined Data.xml // Ideally, you would NOT use a physical data file. Instead you'll have // your own scripts/services/feeds to relay the XML data - dynamically built from // database or other data sources // load XML from external XML // For your real-life project you can pass you XML building Url instead of "Data.xml" xmlData.load("Data.xml"); // We render the chart after XML get loaded from external file // Declare Event handler called when XML loads xmlData.onLoad=function(success) { |
In the above code we have done the following:
Please note that due to security issues, by default, Flash cannot load cross-domain external data unless cross domain xml is defined in the domain containing the swf. |
We next see how to load multiple charts in the same application. |