开发者

Populate FusionCharts with XML data AJAX

开发者 https://www.devze.com 2022-12-12 01:02 出处:网络
Hi I have a js file that uses ajax to get a XML doc from a php script . The XML file forms the data to draw a Fusion Chart. I know I am getting the XML data ok but FusionCharts will not draw it . I wo

Hi I have a js file that uses ajax to get a XML doc from a php script . The XML file forms the data to draw a Fusion Chart. I know I am getting the XML data ok but FusionCharts will not draw it . I would really appreciate any help , thanks

(FusionCharts.js is included earlier in my script) 

if(XMLHttpRequestObject) {

XMLHttpRequestObject.open("GET", "chart.php?job="+job, true);

XMLHttpRequestObject.onreadystatechange = function() { 
if (XMLHttpRequestObject.readyState == 4 &&  XMLHttpRequestObject.status == 200) { 
var xdoc = XMLHttpRequestObject.responseXML;

     var chart1 = new FusionCharts("Pie3D.swf", "chart1Id", "400", "300", "0", "1"); 
 chart1.setDataXML(xdoc);
     chart1.render("chart1div");

chart.php produces this XML data

<chart caption='ADI Chart Test ' >
  <set label='Driver' value='12.25' />
  <set label='Other Staff' value='223.21' />
  <set label='Equipment' 开发者_运维百科value='0.00' />
  <set label='Additional Items' value='0.00' />
  <set label='Vehicle Fuel' value='0.00' />
  <set label='Accomodation' value='0.00' />
  <set label='Generator Fuel' value='0.00' />
</chart>


if(XMLHttpRequestObject) {
    XMLHttpRequestObject.open("GET", "chart.php?job="+job, true);
    XMLHttpRequestObject.onreadystatechange = function() {
        if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) {
            var xdoc = XMLHttpRequestObject.responseXML;
            var chart1 = new FusionCharts("Pie3D.swf", "chart1Id", "400", "300", "0", "1"); 
            chart1.setDataXML(xdoc);
            chart1.render("chart1div");

Thanks.. it worked!!


It looks as though that you have a 'chart1div', even though it i.e. the Div is not defined. For this, you would need to define a Div.

Also, try using responseText in place of responseXML. Here, the former returns a string while the latter returns a XML document object.

Example: var xdoc = XMLHttpRequestObject.responseText;

:)


Does the "Pie3D.swf" live in the same root directory that you're working from?


Try to return the XML as string from chart.php..... And trythe following code.

FusionCharts.RenderChart("/Charts/FCF_Pie3D.swf", "", $strXML, "ResourceVsCO1", "400", "200", false, false);

strXML is the string contain xml return from chart.ph

0

精彩评论

暂无评论...
验证码 换一张
取 消