0

I'd like to plot a simple graph using data from PHP and jqplot.

In PHP I simply did this:

$test = array('1' => '2', '3' => '4'); 
echo json_encode($test); 

The result that I get on js side is: {"1":"2","3":"4"}, I checked this.

So, I've tried to plot this simple array but no luck:

$.ajax({  
      type: "POST",  
      url: "ajax.php",  
      data: "fname="+ fname +"& lname="+ lname,
      dataType:"json", 
      success: function(data)
        {  
        $('#dissapear').hide(function(){$('#chartdiv').css("height:400px;width:300px;");$('#chartdiv').fadeIn();});
        $.jqplot
         ('chartdiv', [data], 
           {
           title:'Jitter',
           axes:{yaxis:{min:0,max:240},xaxis:{renderer:$.jqplot.DateAxisRenderer}},
           series:[{lineWidth:4, markerOptions:{style:'square'}},{ show: true } ]
           }
         );

What did I miss? Please help me out, I've tried at least 20 code combinations but no luck. And yeah, I did look at dataRenderer examples in jqplot, but it didn't help me.

4

2 回答 2

0

我不熟悉 jqplot,但在我看来:

$test = array('1' => '2', '3' => '4'); 

应该是

$test = array(1 => 2, 3 => 4);

也就是说,您不需要数组值是字符串。

于 2011-03-11T17:06:20.050 回答
0

我相信当你返回 json 时问题就来了……你的 javascript 不明白它是一个数组。没有“作为数组”类型转换,所以我在这个问题上摸不着头脑。

于 2011-03-15T21:29:34.553 回答