2017-01-26 151 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'])); 
    }