Php Highcharts,$.getJSON,无运行图
我尝试在一个线形的Highchart中显示从php文件“highchartsFixData.php”传递的一些值,这些值给出:Php Highcharts,$.getJSON,无运行图,php,highcharts,getjson,Php,Highcharts,Getjson,我尝试在一个线形的Highchart中显示从php文件“highchartsFixData.php”传递的一些值,这些值给出: [{"name":"Month","data":["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]},{"name":"Umidita","data":[29.9,71.5,106.4,129.2,144,176,135.6,148.5,216.4,194.1,95.6,54
[{"name":"Month","data":["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]},{"name":"Umidita","data":[29.9,71.5,106.4,129.2,144,176,135.6,148.5,216.4,194.1,95.6,54.4]}]
<pre>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Highcharts Static Data</title>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var option={
chart: {
renderTo: 'container',
type: 'line',
marginRight: 130,
marginBottom: 25
},
title: {
text: 'Highcharts Test',
x: -20 //center
},
subtitle: {
text: '',
x: -20
}
xAxis: {
categories: []
},
yAxis: {
title: {
text: 'Umidita'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -10,
y: 100,
borderWidth: 0
},
series: json
}
$.getJSON("highchartsFixData.php", function(json) {
options.xAxis.categories = json[0]['data'];
options.series[0] = json[1]['data'];
chart = new Highcharts.Chart(options);
});
});
</script>
</head>
<body>
<div id="container" style="min-width: 400px; height: 400px; margin: 0 auto">
</div>
</body>
</html>
</pre>
我不知道这是否是传递数据数组的正确方法,或者下面的代码中有错误
这是highchartsFixData.php
<?php
$rows = array();
$rows['name'] = 'Month';
$rows1 = array();
$rows1['name'] = "Umidita";
$rows["data"] = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
$rows1["data"] = [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4];
$rst = array();
array_push($rst,$rows);
array_push($rst,$rows1);
print json_encode($rst, JSON_NUMERIC_CHECK);
?>
这是index.htm:
海图静态数据
$(文档).ready(函数(){
var期权={
图表:{
renderTo:'容器',
键入:“行”,
marginRight:130,
marginBottom:25
},
标题:{
文本:“高图表测试”,
x:-20/中心
},
副标题:{
文本:“”,
x:-20
}
xAxis:{
类别:[]
},
亚克斯:{
标题:{
文字:“Umitita”
},
绘图线:[{
值:0,
宽度:1,
颜色:'#808080'
}]
},
图例:{
布局:“垂直”,
对齐:“右”,
垂直排列:“顶部”,
x:-10,
y:100,
边框宽度:0
},
系列:json
}
$.getJSON(“highchartsFixData.php”,函数(json){
options.xAxis.categories=json[0]['data'];
options.series[0]=json[1]['data'];
图表=新的高点图表。图表(选项);
});
});
index.html不显示图表,我不知道如何修复它。。
请帮帮我。。
谢谢您可以添加
highchartsFixData.php
代码来创建JSON字符串吗。数据键的valueuseoptions.series=[{name:json[0]['data'],data:json[1]['data']}]中有错误
而不是options.series[0]=json[1]['data']代码>你好,深,谢谢,但它不工作。。。脚本位置是否正常?辛塔克斯?如何测试脚本是否从php读取数组?我会尝试打印接收到的数据,就像正文中的调试消息一样..Doconsole.log(json[0]['data'])
并查看console日志中的数据