2014-11-24 28 views
-1
$http.post(galileoServer + "actions.php", { 
     "action": "get-attendance-graph", 
     "user": window.localStorage.getItem("username") 
    }).success(function(result){ 
     //console.log(result) 
     busyIndicator("hide"); 
     $('#attendance-graph').highcharts({ 
      credits: 0, 
      tooltip:{ 
       enabled: false 
      }, 
      chart: { 
       type: 'bar' 
      }, 
      title: { 
       text: '', 
       style: { 
        display: "none" 
       } 
      }, 
      xAxis: { 
       categories: ['June', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec', 'Jan', 'Feb', 'Mar', 'Apr', 'May'] 
      }, 
      yAxis: { 
       min: 0, 
       title: { 
        text: 'No. of days' 
       }, 
       gridLineWidth: 0, 
       minorGridLineWidth: 0, 
       labels: { //to disable points displayed 
        enabled: false 
       } 
      }, 
      legend: { 
       reversed: true 
      }, 
      plotOptions: { 
       series: { 
        stacking: 'normal', 
        dataLabels: { 
         enabled: true, 
         color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white', 
         formatter: function() { //function to avoid displaying zero values 
          if (this.y != 0) { 
           return this.y; 
          } else { 
           return null; 
          } 
         } 
         /*style: { 
         textShadow: '0 0 3px black, 0 0 3px black' 
         }*/ 
        } 
       } 
      }, 
      series: [{ 
       name: 'Absent', 
       data: [result.absentData] 
      }, { 
       name: 'Present', 
       data: [result.presentData] 
      }] 

     }); 



    }).error(function(result, status){ 
     alert(status + "\nCouldn't connect to Galileo server due to network problem") 
    }); 

我想通過ajax加載數據,但沒有得到加載圖加載的圖是空白的。 提供了編碼片段。 我也嘗試了getJSON部分,但它也沒有奏效。 請讓我知道解決方案,因爲我無法從最近兩天獲取圖表。

控制檯輸出{"absentData":"0,0,2,0,0,1,0,0,0,0,0,0","presentData":"30,31,29,30,31,29,31,31,28,31,30,31"}

+0

空白圖形表示您的數據格式不正確。首先,檢查你的控制檯是否有錯誤。其次,用'console.log(result)'的輸出更新你的問題。在你這樣做之前,我們無法幫助你。 – Mark 2014-11-24 16:03:25

+0

控制檯顯示完美結果。我將附上輸出 – 2014-11-24 17:03:43

+0

@Mark 控制檯輸出爲http://prntscr.com/59p18w – 2014-11-24 17:29:40

回答

1

您的JSON不能正常形成Highcharts。你想要的數字陣列,你給它一個元素的字符串數組:

data: ["0,0,2,0,0,1,0,0,0,0,0,0"] // an array of a single string... 

這是更好,你在你的PHP代碼解決這個問題。您需要構建一個ints的php數組(不要構建連接的字符串),然後使用json_encode

如果你不能在PHP修復它,你可以這樣做:

data: $.parseJSON("["+result.absentData+"]") 

但這是有點醜陋。

+0

它的工作!找到了一個包含你的代碼片段的工作。 – 2014-11-25 07:13:04