Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading 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 the data using jQuery and push the series to the 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);
      }
  });

I end up getting the following error:

Unexpected value NaN parsing y attribute

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

like image 612
Christian Stade-Schuldt Avatar asked Oct 06 '22 15:10

Christian Stade-Schuldt


1 Answers

Aside from the cross-domain issue, the error is due to there being an existing empty series in the plot options. The initial series in the options should be set to:

series: []

instead of:

series: [{ name: 'Temperature', data: [] }]

The subsequent call to options.series.push(series); merely adds a new series leaving the empty one unchanged.

like image 190
Greg Ross Avatar answered Oct 10 '22 02:10

Greg Ross