Using Data String method - XML data embedded in HTML page |
In our previous examples, we had created charts by providing chart data through an external XML file. Here, we'll show you how to embed the XML directly into an HTML page. In our previous examples, we had used the JavaScript function setXMLUrl() to provide URL of the XML file to the chart. Hence, the term Data URL method is used for referring to the technique used earlier. |
Create a copy of customer-satisfaction.html
and save it as customer-satisfaction-dataString.html. Next, modify the code as shown below: |
<html> <head> <title>My First chart using FusionWidgets XT - using XML data embedded in the page</title> <script type="text/javascript" src="Charts/FusionCharts.js"></script> </head> <body> <div id="chartContainer">FusionWidgets XT will load here</div> <script type="text/javascript"><!-- var myChart = new FusionCharts("Charts/AngularGauge.swf", "myChartId", "400", "200", "0"); myChart.setXMLData("<chart lowerLimit='0' upperLimit='100' lowerLimitDisplay='Bad' " + "upperLimitDisplay='Good' numberSuffix='%' showValue='1'>" + "<colorRange>" + "<color minValue='0' maxValue='75' code='FF654F'/>" + "<color minValue='75' maxValue='90' code='F6BD0F'/>" + "<color minValue='90' maxValue='100' code='8BBA00'/>" + "</colorRange>" + "<dials>" + "<dial value='92'/>" + "</dials>" + "</chart>"); myChart.render("chartContainer"); // --> </script> </body> </html> See it live! |
In the above code, we have provided the entire XML data as a string inside the code itself and passed it to the chart using setXMLData() method. There are certain pointers to be kept in mind when using Data String method:
Existing Users: Prior to FusionWidgets XT, while using this method, you need to encode various characters. Since FusionWidgets XT, except for a few characters listed in Using Currency Symbols and Using Special Punctuation pages (from Advanced Charting > Using Special Characters section), no character is required to be encoded while using this process. The new FusionCharts JavaScript Class takes care of everything. |