我有四张高档图表"比较多个系列"在一个视图中 有时他们加载得很好,但有时随机不加载并给出错误:"无法读取属性'键入'未定义"。
我的代码是:http://pastebin.com/3He5ahzd
我不知道我做错了什么。
答案 0 :(得分:1)
这是因为您错误地为图表加载了系列。
重现错误的代码。 Live example
length = 2
错误是由系列数组引起的, var seriesOptionsmaxload = [];
$.getJSON('/test/statistics/5/list?parameter=maxLoad&type=wats', function (max) {
seriesOptionsmaxload[0] = {
name: 'Maksymalne obciążenie',
color: '#ff0000',
data: max
};
$.getJSON('/test/statistics/5/list?parameter=maxLoad&type=perKg', function (max) {
seriesOptionsmaxload[1] = {
name: 'W/kg',
color: '#085fbc',
data: max
};
Highcharts.stockChart('maxLoad', {
...
});
});
但第一个元素未定义。在您的代码中,它是由不正确使用ajax请求引起的。可以在第一个ajax请求填充系列变量之前创建图表。您应该嵌套回调或使用其他方法来防止ajax请求的竞争。
ramesh@ramesh-PC MINGW32 /c/Projects/quickstart (master)
$ node --version
v7.4.0
ramesh@ramesh-PC MINGW32 /c/Projects/quickstart (master)
$ npm --version
4.1.1
$ npm start
> angular-quickstart@1.0.0 start C:\Projects\quickstart
> tsc && concurrently "tsc -w" "lite-server"
node_modules_rr/karma/config.tpl.ts(13,18): error TS1109: Expression expected.
node_modules_rr/karma/config.tpl.ts(13,30): error TS1109: Expression expected.
node_modules_rr/karma/config.tpl.ts(17,13): error TS1109: Expression expected.
node_modules_rr/karma/config.tpl.ts(18,5): error TS1109: Expression expected.
node_modules_rr/karma/config.tpl.ts(22,15): error TS1109: Expression expected.
node_modules_rr/karma/config.tpl.ts(23,5): error TS1109: Expression expected.
node_modules_rr/karma/config.tpl.ts(28,20): error TS1109: Expression expected.
node_modules_rr/karma/config.tpl.ts(28,35): error TS1109: Expression expected.
node_modules_rr/karma/config.tpl.ts(51,16): error TS1109: Expression expected.
node_modules_rr/karma/config.tpl.ts(51,28): error TS1109: Expression expected.
node_modules_rr/karma/config.tpl.ts(56,16): error TS1109: Expression expected.
node_modules_rr/karma/config.tpl.ts(56,26): error TS1109: Expression expected.
npm ERR! Windows_NT 6.1.7600
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\ramesh\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! node v7.4.0
npm ERR! npm v4.1.1
npm ERR! code ELIFECYCLE
npm ERR! angular-quickstart@1.0.0 start: `tsc && concurrently "tsc -w" "lite-server" `
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the angular-quickstart@1.0.0 start script 'tsc && concurrently "tsc -w" "lite-server" '.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the angular-quickstart package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! tsc && concurrently "tsc -w" "lite-server"
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs angular-quickstart
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls angular-quickstart
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! C:\Projects\quickstart\npm-debug.log
答案 1 :(得分:0)
我已经第二次击中了,现在我知道是什么原因造成的。
当您的图形数据具有一系列的数据是这样的:
series: [1, 2, null, 3, 4]
OR
series: [1, 2, undefined, 3, 4]
这将因为highstock.src.js
通过阵列并且检查该类型属性,像这样在每个项目显示,highstock迭代引发此错误:
i = seriesOptions && seriesOptions.length;
while (!value && i--) {
klass = seriesTypes[seriesOptions[i].type]; // ERROR THROWN HERE
if (klass && klass.prototype[key]) {
value = true;
}
}
为防止出现此错误,您可以:
(1)从数组中删除所有的非对象
OR
(2)使用替代系列格式如下:
series: [{
data: [1, 2, undefined, 3, 4]
}]
这将避免这种错误。