Uncaught TypeError: Cannot set property '0' of undefined
See original GitHub issueOne-line summary [问题简述]
An error occurs in type:time graph when animating:
Uncaught TypeError: Cannot set property '0' of undefined
at Vt (echarts.min.js:1)
at onframe (echarts.min.js:1)
at ft.i.onframe (echarts.min.js:1)
at ft.fire (echarts.min.js:1)
at ft.step (echarts.min.js:1)
at wx._update (echarts.min.js:1)
at t (echarts.min.js:1)
Details
After some debugging I found that the error comes from dist/echarts.js line 3442 in interpolateArray function (with arrDim = 2 in my case):
function interpolateArray(p0, p1, percent, out, arrDim) {
var len = p0.length;
if (arrDim == 1) {
for (var i = 0; i < len; i++) {
out[i] = interpolateNumber(p0[i], p1[i], percent);
}
}
else {
var len2 = len && p0[0].length;
for (var i = 0; i < len; i++) {
for (var j = 0; j < len2; j++) {
out[i][j] = interpolateNumber(
p0[i][j], p1[i][j], percent
);
}
}
}
}
because p0, p1 and out arrays do not always have the same length (the data get updated dynamically through server requests and may not be of equal length).
The error disappears if you change the function to:
var len = p0.length;
if (arrDim == 1) {
for (var i = 0; i < len; i++) {
out[i] = interpolateNumber(p0[i], p1[i], percent);
}
}
else {
var len2 = len && p0[0].length;
for (var i = 0; i < len; i++) {
if (!out[i]) // make sure the out[i] will exist
out.push([])
for (var j = 0; j < len2; j++) {
if (p1[i]) // make sure the p1[i] exists in order to interpolate
out[i][j] = interpolateNumber(
p0[i][j], p1[i][j], percent
);
else // if p1[i] does not exist keep p0[i] as is
out[i][j] = p0[i][j];
}
}
}
}
The above code does not throw errors when p0, p1 and out have different lengths. Could you please consider making the above change? Or is there something I do wrong and I should change to avoid the error?
Version & Environment [版本及环境]
- ECharts version [ECharts 版本]: 3.8.5
- Browser version [浏览器类型和版本]: Chrome 61.0.3163.100
- OS Version [操作系统类型和版本]: OS X 10.11.6
Expected behaviour [期望结果]
The expected behaviour is the graphs to not to throw console errors.
ECharts option [ECharts配置项]
option = {
xAxis: [{
type: 'time'
}],
yAxis: [{
type: 'value'
}],
series: [{
name: 'Cost',
type: 'line',
stack: 'f',
areaStyle: {
normal: {
color: "rgba(0,155,155,0.2)"
}
},
data: [] //data get updated dynamically
}]
}
Other comments [其他信息]
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Javascript cannot set property 0 of undefined - Stack Overflow
You haven't assigned "array" to anything, it is not currently an array object · Define array as an array var array=[]; and to...
Read more >TypeError: Cannot set properties of Undefined in JavaScript
The "Cannot set properties of undefined" error occurs when setting a property on an undefined value. To solve the error, conditionally check if...
Read more >Uncaught TypeError: Cannot set property
In JavaScript if a variable has been declared, but has not been assigned a value, is automatically assigned the value undefined . Therefore,...
Read more >TypeError: Cannot set property '0' of undefined
In my constructor I define my variable like this: constructor(){ this.myvar = []; } and then, inside a function, I init the array...
Read more >How To Fix Cannot read Property '0' of Undefined in JS
The Solution · Ensure you are using the correct variable · Perform a simple check on your variable before using it to make...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
各位大佬怎么解决的呀T.T