jqplot传递数组未捕获异常:无数据

时间:2013-03-10 20:55:34

标签: javascript jquery jqplot

我正在尝试将数组的内容传递给jplot函数,但我得到的是无数据。 该数组在php中是json encoden,它是一个关联数组。

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

1 个答案:

答案 0 :(得分: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'
                           }
                       });


             },