Download Highcharts series from XML using jQuery

I am trying to populate a highchart series from an xml source using jQuery. The XML file is an export from RRDTool and has the following format:

<data>
<row><t>1347559200</t><v>2.1600000000e+01</v></row>
<row><t>1347562800</t><v>2.1504694630e+01</v></row>
<row><t>1347566400</t><v>2.1278633024e+01</v></row>
.
.
.
</data>

My approach was to load data using jQuery and click a series on a chart:

$.ajax({
      type: "GET",
      url: "data/data.xml",
      dataType: "xml",
      success: function(xml) {
        var series = {  data: []
                    };

        $(xml).find("row").each(function()
        {
            var t = parseInt($(this).find("t").text())*1000
            var v = parseFloat($(this).find("v").text())
            series.data.push([t,v]);
        });
        options.series.push(series);
      }
  });

As a result, I get the following error:

Unexpected value NaN analysis of y-attribute

I created a JSFiddle to demonstrate the code: http://jsfiddle.net/GN56f/

+5
source share
2 answers

In addition to the problem associated with the cross-domain phenomenon, the error occurs due to the presence of an existing empty series in the graph parameters. The initial series in the parameters should be set:

series: []

instead:

: [{           : "",           : []       }]

options.series.push(series); , .

+2

:

  • var options chart
  • ; options
  • Hava options , Highcharts? series.

? , .

series: [{
    name: 'Temperature',
    data: []
}, {
    data: [// data from xml]
}]
  • , options.series.data.push , setData , , , , success.

.

success: function(xml) {
    $('row', xml).each(function() {
        options.series.data.push([t,v]);
    });
    //@todo: declare chart as global before the ajax function
    chart = new Highcharts.Chart(options);
}
+2
source

All Articles