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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:24:11+00:00 2026-06-07T07:24:11+00:00

This script does not display properly, is there something wrong with it? This has

  • 0

This script does not display properly, is there something wrong with it?

This has missing lines in the display of the browser. I’m using for loops to create a 2-d rectangular coordinate system and would like to know if the code has something wrong with it.

<html>
<head>

<script type="text/javascript">

function start() {

    var winwidth = window.innerWidth;
    var winheight = window.innerHeight;
    var canvas=document.getElementById("myCanvas");
    var ctx=canvas.getContext("2d");
    // Sets size of canvas and interior of canvas to window
    ctx.canvas.width = 1200;
    ctx.canvas.height = 600;
    var cname = "ctx";

    // -------------------------------------------
    ctx.beginPath();
    ctx.lineWidth = 1;
    ctx.strokeStyle = '#ff0000';
    // Origin Y-Axis
    ctx.moveTo(0,300);
    ctx.lineTo(1200,300);
    // Origin X-Axis
    ctx.moveTo(600,0);
    ctx.lineTo(600,600);
    ctx.stroke();
    // -------------------------------------------

    // -------------------------------------------
    ctx.beginPath();
    ctx.lineWidth = 0.5;
    ctx.strokeStyle = '#0000ff';
    majoraxes = new Array();
    j=0;
    // Horizontal Major Axes
    for (hundreth=0; hundreth<7; hundreth++) {
        // Skips past 300
        if (hundreth==3) {
            hundreth=4;
            }
        for (c=0; c<2; c++) {
            if (c==0) {
                majoraxes[j] = cname+".moveTo(0,"+hundreth+"00);";
                j = j+1;
                }
            if (c==1) {
                majoraxes[j] = cname+".lineTo(1200,"+hundreth+"00);";
                j = j+1;
                }
            }
        }
    // Vertical Major Axes
    for (hundreth=0; hundreth<13; hundreth++) {
        // Skips past 600
        if (hundreth==6) {
            hundreth=7;
            }
        for (c=0; c<2; c++) {
            if (c==0) {
                majoraxes[j] = cname+".moveTo("+hundreth+"00,0);";
                j = j+1;
                }
            if (c==1) {
                majoraxes[j] = cname+".lineTo("+hundreth+"00,600);";
                j = j+1;
                }
            }
        }
    for (t=0; t < majoraxes.length; t++) {
        eval(majoraxes[t]);
        }
    ctx.stroke();
    // ---------------------------------------


    // ---------------------------------------
    ctx.beginPath();
    ctx.lineWidth = .2;
    ctx.strokeStyle = '#0000ff';
    minoraxes = new Array();
    j=0;
    // Horizontal Minor Axes
    for (hundreth=0; hundreth<7; hundreth++) {
        for (tenth=1; tenth<10; tenth++) {
            for (c=0; c<2; c++) {
                if (c==0) {
                    minoraxes[j] = cname+".moveTo(0,"+hundreth+""+tenth+"0);";
                    j = j+1;
                    }
                if (c==1) {
                    minoraxes[j] = cname+".lineTo(1200,"+hundreth+""+tenth+"0);";
                    j = j+1;
                    }
                }
            }
        }
    // Vertical Minor Axes
    for (hundreth=0; hundreth<13; hundreth++) {
        for (tenth=1; tenth<10; tenth++) {
            for (c=0; c<2; c++) {
                if (c==0) {
                    minoraxes[j] = cname+".moveTo("+hundreth+""+tenth+"0,0);";
                    j = j+1;
                    }
                if (c==1) {
                    minoraxes[j] = cname+".lineTo("+hundreth+""+tenth+"0,600);";
                    j = j+1;
                    }
                }
            }
        }
    for (t=0; t < minoraxes.length; t++) {
        eval(minoraxes[t]);
        }
    ctx.stroke();
    // --------------------------------------

    }

</script>

<style type="text/css">
html, body {
  width:  100%;
  height: 100%;
  margin: 0px;
}
#myCanvas {
    width:1200;
    height:600;
    image-rendering:optimize-contrast;
}
</style>
</head>
<body onload="start()">

<canvas id="myCanvas" style="border:1px solid #c3c3c3;">
Your browser does not support the canvas element.
</canvas>


</body>
</html>
  • 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-06-07T07:24:12+00:00Added an answer on June 7, 2026 at 7:24 am

    Looks like you weren’t drawing enough lines. You can change these in your version to make it work.

    // Horizontal Minor Axes
        for (hundreth=0; hundreth<7; hundreth++) {
            for (tenth=1; tenth<12; tenth++) { // changed to 12
    
        // Vertical Minor Axes
        for (hundreth=0; hundreth<13; hundreth++) {
            for (tenth=1; tenth<12; tenth++) { // changed to 12
    

    To be honest though you could really shorten up the code a lot, check this out. I also added in the functionality to make the grid any size you want.

    Working Demo

    Full screen demo

    function start() {
        var winwidth = window.innerWidth;
        var winheight = window.innerHeight;
        var canvas=document.getElementById("myCanvas");
        var ctx=canvas.getContext("2d");
        // Sets size of canvas and interior of canvas to window
        var width = 1200,
            height = 600;
    
        canvas.width = width;
        canvas.height = height;
    
        var cname = "ctx";
    
        // -------------------------------------------
        ctx.beginPath();
        ctx.lineWidth = 1;
        ctx.strokeStyle = '#ff0000';
        // Origin X-Axis
        ctx.moveTo(0,height/2);
        ctx.lineTo(width,height/2);
        // Origin Y-Axis
        ctx.moveTo(width/2,0);
        ctx.lineTo(width/2,height);
        ctx.stroke();
        // -------------------------------------------
    
        // -------------------------------------------
        ctx.beginPath();
        ctx.lineWidth = 0.5;
        ctx.strokeStyle = '#0000ff';
        majoraxes = new Array();
        j=0;
    
        for(var hundreth = 0; hundreth < height/100; hundreth++){
            if(hundreth !== (height/2)/100){
                ctx.moveTo(0,hundreth*100);
                ctx.lineTo(width, hundreth*100);
            }
        }
    
        // Vertical Major Axes
        for (hundreth=0; hundreth < width/100; hundreth++) {
            if(hundreth !== (width/2)/100){
                ctx.moveTo(hundreth*100, 0);
                ctx.lineTo(hundreth*100,height);
            }
        }
    
        ctx.stroke();
        // ---------------------------------------
    
        // ---------------------------------------
        ctx.beginPath();
        ctx.lineWidth = .2;
        ctx.strokeStyle = '#0000ff';
        minoraxes = new Array();
        j=0;
    
         for(var tenth= 0; tenth< height/10; tenth++){
            ctx.moveTo(0,tenth*10);
            ctx.lineTo(width, tenth*10);
        }
    
        // Vertical Major Axes
        for (tenth=0; tenth< width/10; tenth++) {
            ctx.moveTo(tenth*10, 0);
            ctx.lineTo(tenth*10,height);
        }
    
        ctx.stroke();
        // --------------------------------------
    }
    

    ​

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why does this script return a pair of nulls? I'm using SQL Server 2008,
EDIT: It does work (sorry). Something in this script is causing it to stop
I am working on a Bash shell script that does something like this: #!/bin/bash
I could use another pair of eyes. This script does what I want in
for the moment the script does like this: click on the link edit the
I have been working on this for some time. The script does work and
I have to write a Matlab script that does this: The input is 2
I have a simple script that does some search and replace. This is basically
What does VAR_NAME=${VAR_NAME:-/some/path/file} mean in an shell script? This is for an init script,
Okay so to make a long story short I am using this script in

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.