FusionCharts for Flex > Chart Creation > Single Series > Data from XML String

You might not always intend to use an XML file for passing data to the chart. You might have built an XML string inside your flex application. FusionCharts for Flex allows you to set an XML string to provide data to the chart. In this section, we will discuss how to render a chart using data from XML string.

 
Before you continue, we recommend you to go through the 'Data from XML File' section, as we start off from the concepts explained in that section.
 
We will continue with the chart that you created in the previous example. Here, instead of providing the XML file's path, we would pass the XML as hard-coded String variable in Flex. The code for this is given below. Please note that in your real application, you might need to build the XML string passing through different data building phases.
 

<?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 x="10" y="10" FCChartType="Column3D" FCDataXML="{xmlData}" />

      <mx:Script>
        <![CDATA[

           //Create a string with valid chart XML.
           [Bindable]
           private var xmlData:String = "<chart caption='Half Yearly Sales Summary'" +
             "subcaption='For the year 2008 - First Half'   xAxisName='Month'" +
             "yAxisName='Sales' numberPrefix='$'>" +
               "<set label='Jan' value='17400'/>"
+
               "<set label='Feb' value='19800'/>" +
               "<set label='Mar' value='21800'/>" +
               "<set label='Apr' value='23000'/>" +
               "<set label='May' value='29000'/>" +
               "<set label='June'value='27600'/>" +
          "</chart>"
;

        ]]>
      </mx:Script>
</mx:Application>

 

As shown by the highlighted portion of the code:

  • We defined a bindable String variable named xmlData.
  • We do not set the XML to FCDataURL attribute. Instead, we bind the string variable to the FCDataXML attribute of the chart component.
Now run the code, the following chart will be rendered:
 
 

To know more about the attributes/parameters like FCDataURL, FCDataXML, FCChartType, etc., please go through Chart API Reference section's FusionCharts Properties page.