0

我正在尝试将数组的内容传递给 jplot 函数,但我没有得到任何数据。该数组已在 php 中进行了 json 编码,它是一个关联数组。

 $.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];但这也不起作用......

4

1 回答 1

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'
                           }
                       });


             },
于 2013-03-11T22:22:10.923 回答