JSON和Highcharts [英] JSON and Highcharts
问题描述
我最近新的使用JSON和我可不是能得出任何实物Highcharts图表。自上周五我正在阅读和阅读在互联网上,我学习了很多,肯定的,但现在我很绝望。我只想要一个简单的酒吧和馅饼!
I'm recently new using JSON and i´m not able to draw any kind of charts from Highcharts. Since last Friday i'm reading and reading over the internet, i'm learning a lot, for sure, but right now i'm desperate. I just want a simple bar and a pie!
这是我的PHP文件,Json_en code打印一些这样的:
From my php file, Json_encode prints something this:
[["January",4],["February",9]]
我认为这是正确的格式,字符串用和int没有它。
I think that is the correct format, string with the "" and int without it.
这是code我想要(我把我的一些网站,我发现整个示例):
And this is the code that i'm trying (i'm putting the entire example from some web i found):
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</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 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("myphpname.php", function(json) {
options.xAxis.categories = json[0]['data'];
options.series[0] = json[1];
chart = new Highcharts.Chart(options);
});
});
</script>
</head>
<body>
<div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
</body>
</html>
感谢所有!
推荐答案
在code就可以了。问题是,我使用的是免费的服务器。有了XAMPP,在本地主机它完美!感谢所有!
The code is ok. The problem was that i was using a free server. With XAMPP, at the localhost it works perfectly! Thanks for all!
这篇关于JSON和Highcharts的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!