从数据库填充flot图

时间:2015-08-04 10:36:20

标签: jquery json

我有以下jQuery代码(我已删除了不适用于此问题的部分):

g_new

console.log(结果)是:

jQuery(document).ready(function () {

  var formData = "f=27/07/2015&t=01/08/2015";

  jQuery.ajax
  ({ 
     url: 'http://www.yourhealthfoodstore.co.uk/test.php',
     type: 'post',
     data : formData,
     success: function(result)
       {

         console.log(result);

         // Graph Data ##############################################
         var graphData = [{
           // Shop                          
           data: result,
           color: '#71c73e'
          }, {
           // Net
           data: [ [1, 900, '27/07'], [2, 1100, '28/07'], [3, 1550, '29/07'], [4, 1600, '30/07'], [5, 1800, '31/07'], [6, 1400, '01/08'], [7, 1300, '02/08'] ],
           color: '#77b7c5',
           points: { radius: 4, fillColor: '#77b7c5' }
          }
         ];

       }

  });

});

图表不会绘制结果变量:

[[1,"1227.14","27.07"],[2,"1530.40","28.07"],[3,"1235.46","29.07"],[4,"1192.65","30.07"],[5,"1599.85","31.07"],[6,"1350.35","01.08"]]

但是,直接粘贴时会绘制结果变量的内容:

data: result,

这有什么理由吗?它没有产生我能看到的任何错误,只是赢得了没有错误。

1 个答案:

答案 0 :(得分:0)

尝试使用dataType:"json"选项绘制图表,例如

jQuery.ajax({ 
   url: 'http://www.yourhealthfoodstore.co.uk/test.php',
   type: 'post',
   data : formData,
   dataType:'json',// use this
   success: function(result) {
      ....