[英]Use JSON with HighCharts and AJAX
I'm lost with the JSON format and HighCharts. 我迷失了JSON格式和HighCharts。 I tried many technics of forums but the result is not good.
我尝试了许多论坛技术,但效果并不理想。
My problem : 我的问题 :
1- OnClick Ajax call a PHP file who generate a JSON like that : 1- OnClick Ajax调用一个PHP文件,该文件生成这样的JSON:
{"col0":["TROUILLE","BOUILLE"],"col1":[4,1],"col2":[6.35,1.59]}
2- I Would Like to choose for example "col1" for xAxys and "col2" for yAxis so that my test 2 -我想选择例如用于Y轴的xAxys所有“col1”和“COL2”,使我的测试
param_connection
contain the conection of DB parameters param_connection
包含数据库参数的部分
options
contain the options parameters of my graphics : options
包含我的图形的options参数:
$.post(
"file_json.php",
param_connection,
function(json) {
options.credits = {enabled: false};
options.series = json;
chart = new Highcharts.Chart(options);},
"json");
Today my result is null... 今天我的结果为空...
Thank you for your help. 谢谢您的帮助。
Geo-x Geo-x
Looks like your json object just isn't the format highcharts wants. 看起来您的json对象不是highcharts想要的格式。
{"x":value, "y":value2}
You'll have to iterate over your returned JSON object, to get it in the format highcharts wants: 您必须遍历返回的JSON对象,使其以highcharts所需的格式获取:
$.post(
"file_json.php",
param_connection,
function(json) {
var jsonData = [];
for(var i=0, row; row = json[i]; i++){
jsonData.push({"x": row['col1'], "y": row['col2']});
}
options.credits = {enabled: false};
options.series = jsonData;
chart = new Highcharts.Chart(options);},
"json");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.