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 6921797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:19:22+00:00 2026-05-27T10:19:22+00:00

I am trying to draw a simple line in html5 and noticed the following

  • 0

I am trying to draw a simple line in html5 and noticed the following problem.

The code below works great. Draws the line correctly

    topcanvas = document.getElementById("topborder");
topcontext = topcanvas.getContext("2d");

topcontext.clearRect(0, 0, topcanvas.width, topcanvas.height);
    topcontext.moveTo(1, 0);
    topcontext.lineTo(4,0);
    topcontext.lineWidth = 3;
topcontext.strokeStyle = "#ff0000";
topcontext.stroke();

The code below should do the exactly same but not sure why, it draws the first line and then I dont see any change. the output is the line from (1000,0) to (4,0) where as I expect the end result to be (1,0) to (4,0)

    topcanvas = document.getElementById("topborder");
topcontext = topcanvas.getContext("2d");

    topcontext.clearRect(0, 0, topcanvas.width, topcanvas.height);
    topcontext.moveTo(1000, 0);
    topcontext.lineTo(4,0);
    topcontext.lineWidth = 3;
topcontext.strokeStyle = "#ff0000";
topcontext.stroke();

topcontext.clearRect(0, 0, topcanvas.width, topcanvas.height);
    topcontext.moveTo(1, 0);
    topcontext.lineTo(4,0);
    topcontext.lineWidth = 3;
topcontext.strokeStyle = "#ff0000";
topcontext.stroke();

The canvas width is 1000 and height 3

  • 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-27T10:19:23+00:00Added an answer on May 27, 2026 at 10:19 am

    To clear canvas do the following:

    topcanvas.width=topcanvas.width;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to draw a simple line graph which would use values from the
I am trying to draw a simple line in WP7 XAML such as the
In the following program i am trying to draw a simple house. The coordinates
I'm trying to draw a single line using OnMouseMove() event. My Problem is that
I'm trying to draw a simple box in my iPhone game. Here is the
So I'm trying to draw a simple rectangle in my iOS cocos2d game, but
I am trying to make a simple line drawing program in java, I am
I am trying to draw a bus route as a simple sequence of lines.
I'm trying to make simple paint application, based on Apple's GLPaint. To draw a
I'm trying to draw a line using ctx.lineTo in loop. I have small function

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.