Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Highchart未使用返回的Ajax数据对象更新_Ajax_Highcharts - Fatal编程技术网

Highchart未使用返回的Ajax数据对象更新

Highchart未使用返回的Ajax数据对象更新,ajax,highcharts,Ajax,Highcharts,我最近开始尝试使用它,这确实令人印象深刻,但我在获取图表以使用jQueryAjax请求返回的数据进行更新时遇到了问题 我的代码如下: $.ajax({ type: "POST", url: "scripts/ajax_testDetails.php", async: true, cache: false, dataType: 'json', timeout: 30000, data: "TestID=" + TestID, success: function(data) { if(data.S

我最近开始尝试使用它,这确实令人印象深刻,但我在获取图表以使用jQueryAjax请求返回的数据进行更新时遇到了问题

我的代码如下:

$.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!

}
}))

正如您所看到的,我使用success数据对象并确认它一切正常,但是当我尝试使用chart.series[].setData()函数中的数据时,它不起作用。不过,测试值似乎工作正常。真的很奇怪,很困惑

非常感谢您的建议


Dan

一种可能性是json数据包含字符串而不是数字。这可能会导致数据系列出现问题。尝试在服务器或javascript中转换为数字,如下所示:

chart.series[0].setData([
   randomBetween(1,10),
   Accur1 * 1,
   data.Accuracy2 * 1,
   Accuracy3 * 1,
   randomBetween(1,10)],false);

“*1”将字符串值转换为数字值。

代码非常混乱。你有两个系列。他们都失败了吗?请用一个失败的系列发布一个简单的例子。你能发布数据的全部内容吗?嗨,两个系列都失败了。我不确定去掉一行是否会使事情简化很多我试图表明,我首先使用/检查数据对象,这一切都很好,但当我使用它来更新序列数据时,它失败了。不过,使用的调试变量和随机数工作得很好。@SteveP我不能全部显示,因为有200多个JSON值,但我已经在完整的字符串上运行了JSONLint,它验证得很好,数据肯定在那里,正如我所看到的,而且以前使用过。