PDA

View Full Version : RadarAxis drawAxis method



radutoev
28 Nov 2011, 1:51 AM
Hello,

I have a radar chart that I've integrated inside the portal example.
When the chart gets rendered I noticed in firebug an error: "sprites[i + j] is undefined".
I've debugged the application and I saw that j is undefined in the method: the only reference to it is a declaration on line 44054, but it is used on line 44101 on the store.each function.
What is the logic behind using the j variable?

tvanzoelen
28 Nov 2011, 1:57 AM
Can you post a small code sample?

radutoev
28 Nov 2011, 2:02 AM
for (i = 0; i < steps; i++) { sprites[i].setAttributes({
x: centerX,
y: centerY,
radius: Math.max(rho * (i + 1) / steps, 0),
stroke: '#ccc'
}, true);
}

store.each(function(rec, j) {
sprites[i + j].setAttributes({
path: ['M', centerX, centerY, 'L', centerX + rho * cos(j / l * pi2), centerY + rho * sin(j / l * pi2), 'Z'],
stroke: '#ccc'
}, true);
});

The problem appears on store.each(function(rec, j)) method body.
j is undefined here.

tvanzoelen
28 Nov 2011, 2:10 AM
Are you shure that i isnt undefined instead of j?

Firebug can be misleading somethimes.

And what is Store, an Ext Array? Can you give its definition.

radutoev
28 Nov 2011, 2:15 AM
store is a reference to the attached Store of the view. It contains data that gets displayed in the chart.
i can't be undefined as its value is set in the for structure. j is undefined as it is not manipulated anywhere inside the body of the function(drawAxis).

tvanzoelen
28 Nov 2011, 2:27 AM
If it is out of scope then it can be undefined. But ok.

its possible that the each function on the store only has one input param. Store.data had three.

So try



store.data.each(function(rec, j) {
sprites[i + j].setAttributes({
path: ['M', centerX, centerY, 'L', centerX + rho * cos(j / l * pi2), centerY + rho * sin(j / l * pi2), 'Z'],
stroke: '#ccc'
}, true);
});

radutoev
28 Nov 2011, 3:57 AM
I think that there might be another issue.
I am really new to javascript so if I write something stupid bellow pardon me :P.
After debugging again the script I noticed the following:
- sprites has 10 items.
- steps in the for structure is equal to 10.
- after completing the for loop i is also 10
- j is undefined. If in javascript we add i + undefined, will that be equal to i?. Say for the sake of argument that it is equal to i, then the error is caused by an index out of bounds as there is no sprites[10].
What now? :)

tvanzoelen
28 Nov 2011, 5:09 AM
yes, i ends up with the value of steps