h all, all here is my html code in which when i declare it as a single data it works fine. But when i declare it as a two dimensional array. its not working. Whats the problem. Can anyone help me. here is the code with bug
<!doctype html>
<html>
<head>
<script type="text/javascript">
window.onload=function()
{
var canvas=document.getElementById('mycanvas');
var ctx=canvas.getContext('2d');
var value=[[10,30,40,60,80],[10,20,30,40,50,90]];
var width=50;
var currx=30;
var i = 0, j;
for(j=0;j<=1;j++)
{
var interval = setInterval(function(){
if (i == value[j].length)
{
clearInterval(interval);
return;
}
var h=value[j][i];
ctx.fillStyle="grey";
ctx.fillRect(currx+2,canvas.height-h+1,width+2,h+2);
ctx.fillStyle="red";
ctx.fillRect(currx,canvas.height-h,width,h);
currx+=60;
i++;
}, 2000);
}
};
</script>
</head>
<body>
<canvas id="mycanvas" height="400" width="400" style="border:1px solid #c3c3c3;">
</body>
</html>
In your code error
value[j] is undefinedoccurs because ajvariable evaluate to value3afterforloop ends. But length ofvaluearray is 2. Use next code as example to avoid this trouble.