2017-01-26 70 views
0

我加載系列後'我加載我的API數據。問題是系列數據未被顯示。我的數據格式與您在製作圖表時剛剛添加系列相同。我已經檢查過我的JSON和所有數據,所有這些都很好。Highcharts不顯示數據

代碼:

var overallGraph; 

$(document).ready(function() { 

    updateGraph(); 

    function updateGraph() { 
     $.post('../api/overall-lookup.php?d=4', function(json) { 
      var guildData = []; 
      var textCData = []; 
      var offiUData = []; 

      for(var i = 0; i < 4; i++){ 
       var data = json['lookup-results'][i]; 
       guildData.push(data['guilds']); 
       textCData.push(data['text_channels']); 
       offiUData.push(data['official_users']); 
      } 

      overallGraph.addSeries({'name': 'guilds', 'data': guildData}, true); 
      overallGraph.addSeries({'name': 'text channels', 'data': textCData}, true); 
      overallGraph.addSeries({'name': 'official users', 'data': offiUData}, true); 
     }); 
    } 

    overallGraph = Highcharts.chart('container', { 
     title: { 
      text: 'Overall Data For FlareBot', 
      x: -20 
     }, 
     xAxis: { 
      title : { 
       text: 'Date' 
      } 
     }, 
     yAxis: { 
      title: { 
       text: 'Amount' 
      }, 
      plotLines: [{ 
       value: 0, 
       width: 1, 
       color: '#808080' 
      }] 
     }, 
     legend: { 
      layout: 'vertical', 
      align: 'right', 
      verticalAlign: 'middle', 
      borderWidth: 0 
     } 
    }); 
}); 

輸出: output

JSON

{ 
    "code": 300, 
    "lookup-results": [ 
    { 
     "date": "2017-01-01", 
     "guilds": "759", 
     "text_channels": "4320", 
     "official_users": "79" 
    }, 
    { 
     "date": "2016-12-31", 
     "guilds": "756", 
     "text_channels": "4409", 
     "official_users": "81" 
    }, 
    { 
     "date": "2016-12-30", 
     "guilds": "717", 
     "text_channels": "4225", 
     "official_users": "82" 
    }, 
    { 
     "date": "2016-12-29", 
     "guilds": "700", 
     "text_channels": "4137", 
     "official_users": "78" 
    } 
    ] 
} 
+0

你可以在這裏粘貼你的json嗎? – morganfree

+0

這裏:https://pastebin.com/bNkhNwf3 @morganfree – bwfcwalshy

回答

1

你有數據串,你需要的數字,所以你必須字符串轉換爲數字。

for(var i = 0; i < 4; i++){ 
     var data = json['lookup-results'][i]; 
     guildData.push(Number(data['guilds'])); 
     textCData.push(Number(data['text_channels'])); 
     offiUData.push(Number(data['official_users'])); 
    }