我从一个API返回了这个json数组。
[
{
"localTimestamp": 1383091200,
"swell": {
"absMinBreakingHeight": 3.255
}
},
{
"localTimestamp": 1383102000,
"swell": {
"absMinBreakingHeight": 2.968
}
}
]我需要让这个与高图表工作,我完全迷路了。数据来自外部API。
我是否需要引入数组并将其更改为适合高图集,还是将高图集指向API的URL,并调整高海图的代码以处理它们发送的内容。
我有我一直在使用的高级图表中的示例代码:
html:
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
</head>
<body>
<script>
$(document).ready(function() {
var options = {
chart: {
renderTo: 'container',
type: 'spline'
},
series: [{}]
};
var url = "jsonp.php?callback=?";
$.getJSON(url, function(data) {
options.series[0].data = data;
var chart = new Highcharts.Chart(options);
});
});
</script>
</script>
</head>
<body>
<div id="container" style="width: 100%; height: 400px; margin: 0 auto"></div>
</body>
</html>
<script type="text/javascript" src="/js/themes/gray.js"></script>
</body>
</html>和我的php代码:
<?php
header("content-type: application/json");
$array = array(7,4,2,8,4,1,9,3,2,16,7,12);
echo $_GET['callback']. '('. json_encode($array) . ')';
?>我知道php是错误的(很明显),我只是不知道如何格式化我的json来与高级图表对话。提前谢谢M
为了明确起见,我正在尝试将我的数据(顶部)转换为php数组(底部) ina格式,该格式可以被高海图读取。
发布于 2013-11-03 11:50:22
您需要将数据(从JSON)转换为正确的格式,如对象数组( [{x:timestamp,waveheight},{timestamp,waveheight]] )或数组(如
[[timestamp,waveheight],[timestamp,waveheight]] 通常,在高级图表中,您需要使用x/y参数,而不是自定义名称。
https://stackoverflow.com/questions/19710895
复制相似问题