我最近开始使用Highchards,这确实令人印象深刻,但是我在获取图表以使用从 jQuery Ajax 请求返回的数据进行更新时遇到问题。
我的代码如下:
$.ajax({
type: "POST",
url: "scripts/ajax_testDetails.php",
async: true,
cache: false,
dataType: 'json',
timeout: 30000,
data: "TestID=" + TestID,
success: function(data) {
if(data.Status == "Success"){
document.title = data.FirstName + " " + data.LastName; // This works fine
$('input[name=TestDate]').val(data.TestDateFormat); // This works fine too
console.log("Accuracy2: " + data.Accuracy2); // This works fine
console.log("TPR2: " + data.TPR2); // This works fine too
var Accur1 = 6; // Used to debug, works fine in chart.series[0].setData()
var NewStuff = new Array(25,15,8,18,5); // Used to debug, works fine in chart.series[3].setData()
var Accuracy3 = data.Accuracy2 // Used to debug, returns 'undefined' when used in chart.series[0].setData()
var chart = $('#HeartGraph').highcharts();
// Anything that use the data object here shows as 'undefined' in yData and doesn't change the graph
chart.series[0].setData([randomBetween(1,10),Accur1,data.Accuracy2,Accuracy3,randomBetween(1,10)],false);
chart.series[3].setData([NewStuff[0],NewStuff[1],randomBetween(1,10),data.TPR2,data.TPR3],false);
chart.redraw(); // When redraws, values change except for the ones that use the data. object!
}
});
如您所见,我使用了成功数据对象并确认一切正常,但是当我尝试使用 chart.series[].setData() 函数中的数据时,它不起作用。测试值似乎工作正常。真的很奇怪也很混乱!
任何意见是极大的赞赏。
担