gpt4 book ai didi

javascript - Highcharts 不显示数据

转载 作者:行者123 更新时间:2023-12-03 05:09:28 27 4
gpt4 key购买 nike

从 API 加载数据后,我正在添加系列。问题是系列数据未显示。我的数据格式与您在制作图表时刚刚添加的系列相同。我已经检查了我的 JSON 和所有传入的数据,一切都很好。

代码:

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"
}
]
}

最佳答案

数据中有字符串,并且需要数字,因此必须将字符串转换为数字。

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']));
}

关于javascript - Highcharts 不显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41883804/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com