Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.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
Javascript 如何将数组中的json插入highcharts?_Javascript_Php_Jquery_Json_Highcharts - Fatal编程技术网

Javascript 如何将数组中的json插入highcharts?

Javascript 如何将数组中的json插入highcharts?,javascript,php,jquery,json,highcharts,Javascript,Php,Jquery,Json,Highcharts,我在php中生成了这样一个数组,其中json嵌套在chartData下的数组中: array:1 [▼ 0 => array:18 [▼ "id" => 1 "chart_title" => "A title" "chart_type" => "line" "chartData" => "[[1470406561000,2116],[1470406561000,2116],[1470406562000,2116]]" ] ]

我在php中生成了这样一个数组,其中json嵌套在
chartData
下的数组中:

array:1 [▼
  0 => array:18 [▼
    "id" => 1
    "chart_title" => "A title"
    "chart_type" => "line"
    "chartData" => "[[1470406561000,2116],[1470406561000,2116],[1470406562000,2116]]"
  ]
]
我想访问这个数组中的
chartData
json,并将其插入到一个系列中

我试过使用:
window['chart'+chartData.id]。系列[0]。添加点(chartData,true,shift)

还有一个
forEach
循环:

chartData.forEach(function(dataPoint){
                        console.log(dataPoint);
                        window['chart' + chartData.id].series[0].addPoint(dataPoint[0], true);
                         dataPoint.slice(0,30).forEach(function(point){
                             window['chart' + chartData.id].series[0].addPoint(point, true, shift);
                         });
                    });
两者都不会在控制台中显示任何错误,并且值也不会显示在图表上。如果I
console.log(数据点)我得到了正确的输出:
[[1470406561002116]、[1470406561002116]、[14704065620002116]


如何将
chartData
json插入到一个系列中

使用jQuery,您可以这样尝试:

    var dataPoint =   [[1470406561000,2116],
                       [1470406561000,2116],
                       [1470406562000,2116]];  

    var chart = $('#chart2').highcharts();
    chart.series[0].setData(dataPoint);

    $('#chart2').highcharts().redraw();

请确保根据您的代码正确更改图表id,即
#chart2

我的问题是jQuery没有在视图上解析JSON,实际上是将其传递给highcharts系列raw。通过添加
jQuery.parseJSON(chartData)它能够正确解析并显示在图表上

感谢@vijayP,如果我在jquery中设置了dataPoint变量,但是如果我尝试使用var
dataPoint=chartData这样的数组来设置它,那么我尝试了这个方法,没有任何问题它像这样绘制图表,所以我现在无法访问您发布的图像。您可以
console.log(chartData)
before语句
dataPoint=chartData并检查它。我控制台记录了数据,输出是
[[1470406561002116],[1470406561002116],[14704065620002116]。
它和另一个一样对吗。。。?控制台有错误吗?从逻辑上讲,它应该可以工作这就解决了它。谢谢你的帮助,维杰