## dataXML method
In our previous examples, we had used the dataURL method to provide data to FusionCharts. In dataURL method, the data is contained in an external physical XML document (like Data.xml) or relayed by a URL (like ReturnXMLData.asp). There also exists another method to provide the XML data to FusionCharts - dataXML method. In this method, the XML Data exists in the same HTML page in which FusionCharts is embedded. When working with this method, you don't need to create the external XML document (like Data.xml). Instead you provide it in the HTML page. Let's quickly see an example of the above.
Using dataXML method in direct HTML embedding
Create a copy of Chart.html and save it as ChartDataXML.html. Also, modify the code as under:
<html> <body bgcolor="#ffffff"> <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="900" height="300" id="Column3D" > <param name="movie" value="../FusionCharts/Column3D.swf" /> <param name="FlashVars" value="&dataXML=<chart caption='Monthly Sales Summary' subcaption='For the year 2006' xAxisName='Month' yAxisName='Sales' numberPrefix='$'><set label='January' value='17400' /><set label='February' value='19800' /><set label='March' value='21800' /><set label='April' value='23800' /><set label='May' value='29600' /><set label='June' value='27600' /><set label='July' value='31800' /><set label='August' value='39700' /><set label='September' value='37800' /><set label='October' value='21900' /><set label='November' value='32900' /><set label='December' value='39800' /></chart>"> <param name="quality" value="high" /> <embed src="../FusionCharts/Column3D.swf" flashVars="&dataXML=<chart caption='Monthly Sales Summary' subcaption='For the year 2006' xAxisName='Month' yAxisName='Sales' numberPrefix='$'><set label='January' value='17400' /><set label='February' value='19800' /><set label='March' value='21800' /><set label='April' value='23800' /><set label='May' value='29600' /><set label='June' value='27600' /><set label='July' value='31800' /><set label='August' value='39700' /><set label='September' value='37800' /><set label='October' value='21900' /><set label='November' value='32900' /><set label='December' value='39800' /></chart>" quality="high" width="900" height="300" name="Column3D" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /> </object> </body> </html>
As you can see above, we have provided the complete data by appending it as a FlashVars attribute in the following format: <PARAM NAME="FlashVars" Value="&dataXML=completeXMLData"> and in the EMBED tag, you'll have to add the following: <EMBED ... FlashVars="&dataXML=completeXMLData"> This way you can have FusionCharts to load data from the same page in which it's embedded.
Using dataXML method while embedding chart using JavaScript
If you're using FusionCharts JavaScript class to embed the chart, you can use dataXML with it as under:
<html> <head> <script language="JavaScript" src="../FusionCharts/FusionCharts.js"></script> </head> <body bgcolor="#ffffff"> <div id="chartdiv" align="center">The chart will appear within this DIV. This text will be replaced by the chart.</div> <script type="text/javascript"> var myChart = new FusionCharts("../FusionCharts/Column3D.swf", "myChartId", "900", "300", "0", "0"); myChart.setDataXML("<chart caption='Monthly Sales Summary' subcaption='For the year 2006' xAxisName='Month' yAxisName='Sales' numberPrefix='$'><set label='January' value='17400' /><set label='February' value='19800' /><set label='March' value='21800' /><set label='April' value='23800' /><set label='May' value='29600' /><set label='June' value='27600' /><set label='July' value='31800' /><set label='August' value='39700' /><set label='September' value='37800' /><set label='October' value='21900' /><set label='November' value='32900' /><set label='December' value='39800' /></chart>"); myChart.render("chartdiv"); </script> </body> </html>
You can clearly see above, that instead of using setDataURL method to provide the path of XML file, here we've used setDataXML method to provide the full XML data itself. When you now view the charts, you'll get the same output as before.
With this method, however, there can sometimes be problems when you're working with larger chunks of data. This problem happens due to the limitation on dataXML string length imposed by the browser. When you specify a larger chunk of data using dataXML method, the browser ignores everything after a certain length. This causes FusionCharts to hang (nothing would be displayed on-screen) as the full data has not been supplied to it. Therefore, dataURL method is recommended for larger chunks of data (basically - multi-series/combination charts).