Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6608679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:38:07+00:00 2026-05-25T19:38:07+00:00

I want to draw one line then wait for some milliseconds then draw next

  • 0

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(like ECG waveform).
How i can do that in this code?
This is my code:

<!DOCTYPE html>
<html>
<head>

<script type="text/javascript">

    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<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();
   }

 </script>
 </head>
 <body onload="init()">

  <canvas id="graphSpace" width="800" height="400" style="background-color:      #ffff00;"></canvas>

  </body>
  </html>

I have tried with setInterval

setInterval(function () {
    drawLine(context,startx,starty,copyendx,copyendy);
}, 100);

but i didn’t get desired output.
I want wait for some milliseconds before calling method drawLine(contextO, startx, starty, endx, endy) for each line drawing

I got solution for above problem. i have following problem

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:38:08+00:00Added an answer on May 25, 2026 at 7:38 pm

    The concept of a loop with sleep(100) is something that is not designed to be done in javascript.

    get rid of the loop, do something like this:

    var x,y,i=0;
    setTimeout(function doDraw() {
        var startx=5+x;
        var starty=150-(data[i]*y);
        var endx=(5+x)+1;
        var endy=150-(data[i]*y);
        drawline(yourargs);
        i++;
        if (i < data.length) {
             setTimeout(doDraw, 100);
        }
    }, 100);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to draw line, i have two textfiled in which i enter some
I want to draw line from one point to another unknown point.I want to
I want to plot a line from one well-defined point to another and then
I want to understand how I would draw a line between two shapes that
I want to draw a 3d line from one 3d point to another 3d
i want to create one app which draw different charts like pie chart, line
I've one ImageView in which I want to draw a Line. I've done the
I want to draw 2 different type series (i.e. Column & Line) on one
Hello I want to draw 40 ellipses on one big ellipse. ITS STRANGE. for
I want to draw some Rectangle over a single Image . For example I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.