我正在尝试通过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]]}]
PHP-MySQL结果转换为JSON - php
我试图了解如何将MySQL结果转换为JSON格式,以便以后可以在Javascript中使用此JSON来构建HTML表。但是我的代码只是产生大量的空值,我还不明白为什么。$result = mysqli_query($con, "SELECT * FROM Customers"); $test = json_encode($result);…PHP Count数组元素 - php
嗨,有人可以解释为什么这会返回“数组由0个元素组成”。 :$arr = array(1,3,5); $count = count($arr); if ($count = 0) { echo "An array is empty."; } else { echo "An array has $count elements.…PHP:从函数返回值并直接回显它? - php
这可能是一个愚蠢的问题,但是……的PHPfunction get_info() { $something = "test"; return $something; } html
我有一个巨大的二维PHP数组,带有500万行。$t = [ [ "id" => 1, "name" => "foo" ], [ "id" => 2, "name" => "bar" ] ]; 现在,我必须将此数组的I…PHP str_replace是否具有大于13个字符的限制? - php
直到击中第13个字符为止。一旦str_ireplace在cyper数组中击中“ a”,str_ireplace就停止工作。数组的大小有限制吗?请记住,如果键入“ abgf”,我会得到“ nots”,但是如果键入“ abgrf”,我应该得到“ notes”,那么我就会得到“ notrs”。机架使我的大脑无法解决。$_cypher = array("n…