admin管理员组文章数量:1332389
Sorry for the beginner question.
This is how my JSON looks like:
[
["junior college", "Primary", "secondary", "polytechnic"],
["4", "3", "1", "1"]
]
And this is my HTML,
var chart; // global
var options = {
chart: {
renderTo: 'container',
defaultSeriesType: 'bar'
},
title:{
text: 'No. Schools for different levels'
},
xAxis:{
title:'Education Level',
categories:[]
},
yAxis:{
title:{
text:'No. Of Schools'
}
},
series:[{
name: "No. Schools",
data: []
}]
};
$.getJSON('loadData.php', function(JSONresult) {
yData = options.series[0].data; //Array to store data for y column
xData = options.xAxis.categories; //Array to store data for x column
xDataObj = JSONresult[0];
yDataObj = JSONresult[1];
for(var key in xDataObj){
xData.push(xDataObj[key]);
}
for(var key in yDataObj){
yData.push(parseFloat(yDataObj[key]));
}
I tried to execute the code, firebug shows no error but the chart never shows up. Could you help point out where did I go wrong?
Sorry for the beginner question.
This is how my JSON looks like:
[
["junior college", "Primary", "secondary", "polytechnic"],
["4", "3", "1", "1"]
]
And this is my HTML,
var chart; // global
var options = {
chart: {
renderTo: 'container',
defaultSeriesType: 'bar'
},
title:{
text: 'No. Schools for different levels'
},
xAxis:{
title:'Education Level',
categories:[]
},
yAxis:{
title:{
text:'No. Of Schools'
}
},
series:[{
name: "No. Schools",
data: []
}]
};
$.getJSON('loadData.php', function(JSONresult) {
yData = options.series[0].data; //Array to store data for y column
xData = options.xAxis.categories; //Array to store data for x column
xDataObj = JSONresult[0];
yDataObj = JSONresult[1];
for(var key in xDataObj){
xData.push(xDataObj[key]);
}
for(var key in yDataObj){
yData.push(parseFloat(yDataObj[key]));
}
I tried to execute the code, firebug shows no error but the chart never shows up. Could you help point out where did I go wrong?
Share edited Jul 3, 2011 at 21:20 NT3RP 15.4k9 gold badges63 silver badges97 bronze badges asked Jul 3, 2011 at 16:17 GerardGerard 5133 gold badges7 silver badges14 bronze badges 2- 2 Is there something missing from your code? It looks like you never actually create a new instance of your chart. – NT3RP Commented Jul 3, 2011 at 20:37
-
@NT3RP sorry, i forgot to put the instantiate code here, i did initialize it with
chart = new Highcharts.Chart(options);
but the chart never shows up. Thank you! – Gerard Commented Jul 3, 2011 at 23:57
2 Answers
Reset to default 2I found out the solution.
In my php script, I have to cast integer to the series data,
(int)$variable;
so the JSON out put would be
[4, 3, 1, 1]
and the chart will be rendered.
Thank you ppl :)
You need to do something like this to instantiate and render the chart:
chart = new Highcharts.Chart(options);
This could go at the end of your getJSON response function.
本文标签: javascriptHighcharts How to load data from JSON to xAxiscategories and seriesdataStack Overflow
版权声明:本文标题:javascript - Highcharts: How to load data from JSON to xAxis.categories and series.data? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742291526a2447885.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论