dtds8802 2013-03-04 03:09
浏览 70
已采纳

更新Flot PHP,AJAX,JSON

I am having some trouble updating a Flot bar chart from an Ajax request to a PHP script that returns JSON data.

The PHP script is:

$vars = array(
    'result' => "success",
    'msg' => AJAX_SUCCESS,
    'series' => "Group One,80,Group Two,10" 
    );
echo json_encode($vars);

This is returned to a variable 'series'

var data = [series.series];

This outputs to the console:

Group One,80,Group Two,10

I also have a commented out variable which is:

//var datatwo = [ ["Group One", 80], ["Group Two", 10] ];

This also outputs to the console

Group One,80,Group Two,10

The actual javascript to create the graph is

$.plot("#group-month-graph", [data], options);

The options are assigned at another location of the script.

Im trying to figure out what Im doing wrong as when I alert the returned data or output it to the console the values are identical, however the returned data will not draw the graph whereas if I use the commented out value it does.

Hope that makes sense. I have cut down the full script as I dont think that the issue lies anywhere else.

  • 写回答

1条回答

  • dq_1984 2013-03-04 03:30
    关注

    You are returning a String while the plugin is expecting an Array. You should return [["Group One",80],["Group Two",10]]

    Change your php series structure to:

    $vars = array(
        'result' => "success",
        'msg' => AJAX_SUCCESS,
        'series' => array(array("Group One",80),array("Group Two",10))
    );
    

    Also, you should be getting the series array using data and not [data]

    $.plot("#group-month-graph", data, options);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置