我正在尝试通过jQuery ajax调用从php调用传递json到highcharts对象。
这是PHP脚本的回报
[{"name":"Positive","data":"[1426896000000,0.5,1],[1427760000000,0.333333333333,1],[1427846400000,0.333333333333,1],[1427932800000,0.353553390593,1],[1428278400000,0.408248290464,1],[1428364800000,0.301511344578,1],[1428451200000,0.377964473009,1],[1428537600000,0.686886723927,2],[1428624000000,2.38658259877,7],[1428710400000,0.4472135955,1],[1428883200000,0.333333333333,1],[1429142400000,0.333333333333,1],[1429574400000,0.316227766017,1],[1429747200000,1.10948233661,2],[1429833600000,0.408248290464,1],[1429920000000,1.34375333838,3],[1430092800000,1.13976615407,3]"},{"name":"Negative","data":"[1427673600000,-0.353553390593,1],[1428105600000,-0.353553390593,1],[1428278400000,-1.0850712542,3],[1428537600000,-1.20901527656,3],[1428624000000,-0.377964473009,1],[1428883200000,-0.353553390593,1],[1429056000000,-0.408248290464,1],[1429574400000,-0.377964473009,1],[1429660800000,-0.353553390593,1],[1429747200000,-1,3],[1429833600000,-1.02022005726,3],[1429920000000,-0.755928946018,2],[1430006400000,-0.632455532034,1]"}]
我使用以下方法调用getChart:
function getChart(searchstring){
$.ajax({
type: "GET",
url: "searchString.php",
dataType: "json",
data: {name:searchstring},
success: function(news) {
renderPosNegChart(news);
}
});
}
function renderPosNegChart(data){
var newschart = {
chart: {
type: 'spline'
},
title: {
text: "Test"
},
xAxis: {
type: "datetime"
},
yAxis: {
},
series: [data[0]]
}
$("#newschart").highcharts(newschart);
}
不幸的是,它显示的只是:
最终,我希望它同时显示“正”和“负”行。我在网上跟踪了一堆教程,但是并没有帮助。
如果我可以澄清任何事情,请告诉我。
最佳答案
每个系列数据应该是一个数组数组,而不是字符串。
例:
[{"name":"Positive","data":[[1426896000000,0.5,1], ... ,[1430006400000,-0.632455532034,1]]}]