Skip to content

Instantly share code, notes, and snippets.

@hobopanda
Forked from Tafkas/createhighchartfromxml.js
Created February 23, 2017 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hobopanda/49b44264065d70081765a4c934a69a5e to your computer and use it in GitHub Desktop.
Save hobopanda/49b44264065d70081765a4c934a69a5e 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