0

But now I have other problem. I dont know how to get value from cwok from XML each 5 second

XML Files

<user name="Name1" status="online" ip="0.0.0.0">
 <stats>
   <cwok>100</cwok>
   <cwnok>0</cwnok>
   <cwignore>0</cwignore>
 </stats>
</user>
<user name="Name2" status="online" ip="0.0.0.0">
 <stats>
   <cwok>200</cwok>
   <cwnok>0</cwnok>
   <cwignore>0</cwignore>
 </stats>
</user>

Highcharts script to read data from XML

 // Load the data from the XML file
 $.get('oscamapi.html?part=userstats', function(xml) {

     // Split the lines
     var $xml = $(xml);

     // push series
     $xml.find('user').each(function(i, series) {

          var seriesOptions = {
              name: $(series).attr('name'),
              data: []
              };

          // push data points
          $(series).find('stats cwok').each(function(i, point) {
                  seriesOptions.data.push(
                          parseInt($(point).text())
                   );
          });

         // add it to the options
         options.series.push(seriesOptions);
     });
     var chart = new Highcharts.Chart(options);
   });
});

Thanks for your idea and help

4

1 回答 1

0

需要在setInterval()中调用ajax,然后获取数据。我假设您想从 secong 用户部分获取数据:

    <user name="Name2" status="online" ip="0.0.0.0">
 <stats>
   <cwok>200</cwok>
   <cwnok>0</cwnok>
   <cwignore>0</cwignore>
 </stats>
</user>

因此,您可以对 XML 使用相同的解析器,但需要修改用户行:

$xml.find('user[name="Name2"]')

阿贾克斯:

 chart:{
    events:{
       load:function(){
          setInterval(function(){
              $.ajax()...
          },1000);
       }
    }
}
于 2013-06-05T09:00:18.273 回答