gpt4 book ai didi

php - 如何从 php 发送 json 到 highcharts

转载 作者:行者123 更新时间:2023-12-01 07:51:14 24 4
gpt4 key购买 nike

我正在尝试通过 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);

}

不幸的是,它显示的只是: enter image description here最终,我希望它同时显示“正”线和“负”线。我已经遵循了很多在线教程,但它们没有帮助。

如果我可以澄清任何事情,请告诉我。

最佳答案

每个系列数据应该是数组的数组,而不是字符串。

示例:

[{"name":"Positive","data":[[1426896000000,0.5,1], ... ,[1430006400000,-0.632455532034,1]]}]

关于php - 如何从 php 发送 json 到 highcharts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29897937/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com