[英]jQuery pushing additional calculated data points to HighChart series
我正在嘗試將數據點推送到HighCharts的數據系列數組。 我已經開始使用標准餅圖模板了。 然后我添加了額外的$ .get語句來計算文件中的行數。 每個額外$ .get上的alert語句返回正確的行數,但數據點不會推送到該系列。 任何人都可以幫助我,我是JQuery的新手。 謝謝。
$.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);
});
該數據點是 ,我會承擔,被推到系列,但問題就在於,這不會發生,你已經創建並呈現圖表實例后,直到。
暫且沒有看到我的代碼中沒有聲明options
變量的事實,這表明可能存在潛伏的另一個錯誤(但我認為這只是一個錯字?),問題在於HighCharts不會跟蹤您傳遞的初始系列,因此修改該系列不會影響圖表。
您需要自己更新圖表 - 例如,使用HighCharts系列對象的addPoint方法 。 因此,在Ajax調用的成功回調中,您需要執行以下操作:
$.get('button0.txt', function(data) {
// Split the lines
var lines = data.split('\n'),
chart = $('#container').highcharts();
chart.series[0].addPoint({
name: 'Power off',
y: lines.length-1
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.