-
-
Save hobopanda/637f720014858df6baa262f75036f74d to your computer and use it in GitHub Desktop.
Parse xml file generated from RRDTool export and create Highchart series
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.ajax({ | |
type: "GET", | |
url: "data/temperature24h.xml", | |
dataType: "xml", | |
success: function(xml) { | |
var series = [] | |
//define series | |
$(xml).find("entry").each(function() { | |
var seriesOptions = { | |
name: $(this).text(), | |
data: [] | |
}; | |
options.series.push(seriesOptions); | |
}); | |
//populate with data | |
$(xml).find("row").each(function() { | |
var t = parseInt($(this).find("t").text()) * 1000 | |
$(this).find("v").each(function(index) { | |
var v = parseFloat($(this).text()) | |
v = v || null | |
if (v != null) { | |
options.series[index].data.push([t, v]) | |
}; | |
}); | |
}); | |
options.title.text = "Temperatures of the last 24h" | |
$.each(series, function(index) { | |
options.series.push(series[index]); | |
}); | |
chart = new Highcharts.Chart(options); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment