Note that there are some explanatory texts on larger screens.

plurals
  1. POcan not wait for some milliseconds in javascript
    primarykey
    data
    text
    <p>I want to draw one line then wait for some milliseconds then draw next line again wait for next line and so on, so that its visualize that how line by line it will be drawn(<strong>like ECG waveform)</strong>. How i can do that in this code? This is my code:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;script type="text/javascript"&gt; var ms = 0; var y=5; var x=5; var copyendx=0; var copyendy=0; var context; var temp,total=0; //var data=new Array(-1,3,-3,-7,5,1,-1,-3,2,5,7,7,7,7,1,3,3,4-,8,5,6,6,7,7); var data=new Array(-1,3,-3,-7,5,1,-1,-3,2,5,7,7,7,7,4,7,9,2,2,8); //alert(data); function init() { var graphCanvas = document.getElementById('graphSpace'); context =graphCanvas.getContext('2d'); drawgraph(); } function drawgraph() { drawLine(context,5,50,5,250); drawLine(context,5,150,7,150); // setTimeout(drawgraph(),600); for (var i=0;i&lt;data.length;i++) { var startx=5+x; var starty=150-(data[i]*y); var endx=(5+x)+1; var endy=150-(data[i]*y); if (i==0) { copyendx=endx; copyendy=endy; startx=5+x; starty=150; } //draw line and wait for some milliseconds setInterval(function () { drawLine(context,startx,starty,copyendx,copyendy); }, 100); drawLine(context,startx,starty,copyendx,copyendy); x=x+5; // pausecomp(100); copyendx=endx; copyendy=endy; } } } //Draw line function function drawLine(contextO, startx, starty, endx, endy) { contextO.beginPath(); contextO.moveTo(startx, starty); contextO.lineTo(endx, endy); contextO.closePath(); contextO.stroke(); } &lt;/script&gt; &lt;/head&gt; &lt;body onload="init()"&gt; &lt;canvas id="graphSpace" width="800" height="400" style="background-color: #ffff00;"&gt;&lt;/canvas&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>I have tried with setInterval </p> <pre><code>setInterval(function () { drawLine(context,startx,starty,copyendx,copyendy); }, 100); </code></pre> <p>but i didn't get desired output. I want wait for some milliseconds before calling method <code>drawLine(contextO, startx, starty, endx, endy)</code> for each line drawing </p> <p>I got solution for above problem. i have following problem</p> <p>If i want to draw more points on canvas if that points not fit on my canvas width i am redrawing the canvas but here is problem that my graph is not looking steady (as like ECG wave form applicaion) during first redraw it looks slower, during second redraw it looking faster than first redraw ,during third redraw it looks faster than second redraw and so on. How to overcome that? I want steady flow till i draw my last graph point.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload