Javascript Highcharts(cloumn图表)不显示任何内容,只显示空白html页面
我尝试使用Highcharts教程中给出的柱状图示例。这段代码应该可以正常工作。有人请帮我解决这个问题。我附上下面的代码。我不知道为什么它只显示空白页Javascript Highcharts(cloumn图表)不显示任何内容,只显示空白html页面,javascript,php,html,json,highcharts,Javascript,Php,Html,Json,Highcharts,我尝试使用Highcharts教程中给出的柱状图示例。这段代码应该可以正常工作。有人请帮我解决这个问题。我附上下面的代码。我不知道为什么它只显示空白页 <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Column chart with data from MyS
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Column chart with data from MySQL using Highcharts</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var options = {
chart: {
renderTo: 'container',
type: 'column',
marginRight: 130,
marginBottom: 25
},
title: {
text: 'Project Requests',
x: -20 //center
},
subtitle: {
text: '',
x: -20
},
xAxis: {
categories: []
},
yAxis: {
title: {
text: 'Requests'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+
this.x +': '+ this.y;
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -10,
y: 100,
borderWidth: 0
},
series: []
}
$.getJSON("data.php", function(json) {
options.xAxis.categories = json[0]['data'];
options.series[0] = json[1];
options.series[1] = json[2];
options.series[2] = json[3];
chart = new Highcharts.Chart(options);
});
});
</script>
</head>
<body>
<div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
</body>
</html>
使用Highcharts从MySQL获取数据的柱状图
$(文档).ready(函数(){
变量选项={
图表:{
renderTo:'容器',
键入:“列”,
marginRight:130,
marginBottom:25
},
标题:{
文本:“项目请求”,
x:-20/中心
},
副标题:{
文本:“”,
x:-20
},
xAxis:{
类别:[]
},
亚克斯:{
标题:{
文本:“请求”
},
绘图线:[{
值:0,
宽度:1,
颜色:'#808080'
}]
},
工具提示:{
格式化程序:函数(){
返回“+this.series.name+”
+
this.x+':'+this.y;
}
},
图例:{
布局:“垂直”,
对齐:“右”,
垂直排列:“顶部”,
x:-10,
y:100,
边框宽度:0
},
系列:[]
}
$.getJSON(“data.php”,函数(json){
options.xAxis.categories=json[0]['data'];
options.series[0]=json[1];
options.series[1]=json[2];
options.series[2]=json[3];
图表=新的高点图表。图表(选项);
});
});
这里是data.php。我认为这个php没有什么错
<?php
$con = mysql_connect("localhost","*****","*******");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test_youtube", $con);
$query = mysql_query("SELECT month, wordpress, codeigniter, highcharts FROM project_requests");
$category = array();
$category['name'] = 'Month';
$series1 = array();
$series1['name'] = 'Wordpress';
$series2 = array();
$series2['name'] = 'CodeIgniter';
$series3 = array();
$series3['name'] = 'Highcharts';
while($r = mysql_fetch_array($query)) {
$category['data'][] = $r['month'];
$series1['data'][] = $r['wordpress'];
$series2['data'][] = $r['codeigniter'];
$series3['data'][] = $r['highcharts'];
}
$result = array();
array_push($result,$category);
array_push($result,$series1);
array_push($result,$series2);
array_push($result,$series3);
print json_encode($result, JSON_NUMERIC_CHECK);
mysql_close($con);
?>
你能发布你从grom php获得的json数据吗?{“名称”:“月份”、“数据”:[“一月”、“二月”、“三月”、“四月”、“五月”、“六月”、“七月”、“八月”、“九月”、“十月”、“十一月”、“十二月”],{“名称”:“Wordpress”,“数据”:[4,5,6,2,5,7,2,1,6,7,3,4]},{“名称”:“CodeIgniter”,“数据”:[5,2,3,6,6,6,6,7,1,2,6,3]},{“名称”:“Highcharts”,“数据”:[7,8,9,6,7,10,9,7,6,9,8,4]}它看起来像是不正确的json,因为它应该在任何数组/对象中。@SebastianBochan我对json都是新手。我不太理解你的回答。我们可以详细讨论一下吗?例如,代码的哪一部分需要更改?我建议访问php手册中的json_encode子页面,那里有很多示例。希望这会有所帮助。Additioanl你可以在jslint.com上验证你的json