2013-03-10 25 views
0

我想將數組的內容傳遞給jplot函數,但是我得到了沒有數據。 該數組在php中是json encoden,它是一個關聯數組。jqplot傳遞數組未捕獲的異常:沒有數據

$.ajax({ 
      type: "POST", 
      url: "actions/myphp.php", 
      data: PassArray, 
      dataType: 'json', 
      beforeSend: function (html) { // this happens before actual call 
      // alert(html); 
      }, 
success: function (html) { // this happens after we get results 
       // $("#loginoutcome").text(html); 
       // alert(html); 
       var obj =html ; 
       // Now the two will work 
       $.each(obj, function(key, value) { 
         alert(key + ' ' + value); 
       }); 


       var s1 = obj; 
         var plot8 = $.jqplot('pie8', [s1], { 
          grid: { 
           drawBorder: false, 
           drawGridlines: false, 
           background: '#ffffff', 
           shadow: false 
          }, 
          axesDefaults: {}, 
          seriesDefaults: { 
           renderer: $.jqplot.PieRenderer, 
           rendererOptions: { 
            showDataLabels: true 
           } 
          }, 
          legend: { 
           show: true, 
           rendererOptions: { 
            numberRows: 1 
           }, 
           location: 's' 
          } 
         }); 

我也嘗試過使用var s1 = [obj];但沒有也行通...

+0

任何錯誤的工作?你可以看看Firebug中的ajax調用嗎? POST的結果是什麼? – Owlvark 2013-03-10 22:52:06

+0

請讓我們看看s1的內容。您可以在Ajax調用後使用console.log(s1) – AnthonyLeGovic 2013-03-11 07:29:55

回答

1

這就是現在我沒有使用數組正確

success: function (html) { // this happens after we get results 

       // alert(html); 
       var obj =html ; 
       // Now the two will work 
       $.each(obj, function(key, value) { 
         alert(key + ' ' + value); 
         myArr.push([key, value]); 
       }); 


        s1 = myArr; 
         var plot8 = $.jqplot('pie8', [s1], { 

          seriesColors: [ "#EB0712", "#12C456", "#EAA228", "#579575", "#839557", "#958c12", 
              "#953579", "#4b5de4", "#d8b83f", "#ff5800", "#0085cc"], 
          grid: { 
           drawBorder: false, 
           drawGridlines: false, 
           background: '#ffffff', 
           shadow: false 

          }, 
          axesDefaults: {}, 
          seriesDefaults: { 
           renderer: $.jqplot.PieRenderer, 
           rendererOptions: { 
            showDataLabels: true 
           } 
          }, 
          legend: { 
           show: true, 
           rendererOptions: { 
            numberRows: 1 
           }, 
           location: 's' 
          } 
         }); 


      },