Skip to content

Instantly share code, notes, and snippets.

@Tafkas
Last active February 23, 2017 16:09
Show Gist options
  • Save Tafkas/7449424 to your computer and use it in GitHub Desktop.
Save Tafkas/7449424 to your computer and use it in GitHub Desktop.
Parse xml file generated from RRDTool export and create Highchart series
$.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