dimanche 22 février 2015

jQuery pushing additional calculated data points to HighChart series


I am trying to push data points to a data series array for HighCharts. I have started with the standard pie template. I have then added additional $.get statements to calculate the number of lines in the files. The alert statement on each additional $.get returns the correct number of lines, but the data point is not pushed to the series. Can anyone help me, I am new to JQuery. Thanks.



$.get('piechart.csv', function(data) {
// Split the lines
var buttons
var lines = data.split('\n');
var series = {
data: []
};
// Iterate over the lines and add categories or series
$.each(lines, function(lineNo,line) {
var items = line.split(',');
series.data.push({
name: items[0],
y:parseFloat(items[1])
});
});


$.get('button0.txt', function(data) {
// Split the lines
var lines = data.split('\n');
series.data.push({
name: 'Power off',
y: (lines.length-1)
});
alert (lines.length-1);
});
$.get('button1.txt', function(data) {
// Split the lines
var lines = data.split('\n');
series.data.push({
name: 'Power on',
y: (lines.length-1)
});
alert (lines.length-1);
});

options.series.push(series);
// Create the chart
var chart = new Highcharts.Chart(options);
});




Aucun commentaire:

Enregistrer un commentaire