我有这个脚本
var portfolio_in_arrears = [];
var portfolio_future = [];
var portfolio_good_standing = [];
var portfolio_ingrace_period = [];
$.each(JSON.parse(response.portfolio), function(index, value){
portfolio_in_arrears.push(value.in_arrears);
portfolio_future.push(value.future_clients);
portfolio_good_standing.push(value.good_standing);
portfolio_ingrace_period.push(value.grace_period);
});
以及这部分高潮图选项
series: [{
name: 'Future',
data: portfolio_future //sample [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
}, {
name: 'In Grace Period',
data: portfolio_ingrace_period //sample [-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5]
}, {
name: 'Arrears',
data: portfolio_in_arrears //sample [-0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0]
}, {
name: 'Good standing',
data: portfolio_good_standing //sample [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
}]
我成功检索并解析了json响应中的数据并在那里放置了相应的数组
var portfolio_in_arrears = [];
var portfolio_future = [];
var portfolio_good_standing = [];
var portfolio_ingrace_period = [];
但遗憾的是,当我试图将这些数组绑定在系列选项上时,它没有用。当我在控制台上检查时,例如console.log(portfolio_future),我看到像这样的数组
["146", "143", "123", "106", "106", "94", "76", "71", "69", "83", "66", "66", "98", "98", "96", "90", "85", "102", "102", "94", "135", "126", "111", "125", "116", "116", "108", "129", "113", "93", "102", "86", "86", "68", "81"]
系列选项的正确数组是
[3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
所以任何想法如何转变
["146", "143", "123", "106", "106", "94", "76", "71", "69", "83", "66", "66", "98", "98", "96", "90", "85", "102", "102", "94", "135", "126", "111", "125", "116", "116", "108", "129", "113", "93", "102", "86", "86", "68", "81"]
到
[146, 143, 123, 106, 106, 94, 76, 71, 69, 83, 66, 66, 98, 98, 96, 90, 85, 102, 102, 94, 135, 126, 111, 125, 116, 116, 108, 129, 113, 93, 102, 86, 86, 68, 81]
正如你所看到的,每个数字上都没有双重qoutes内容。
答案 0 :(得分:1)
您可以通过指定严格数值来解决此问题。使用parseInt()函数
以下是您将如何使用它。
portfolio_in_arrears.push(parseInt(value.in_arrears));
示例here。
答案 1 :(得分:0)
最简单的方法是将数组map
放到Number
构造函数上,如下所示:
portfolio_future = portfolio_future.map(Number);