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

The Archive Base Latest Questions

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

i am trying to join each circle via line and my final code does

  • 0

i am trying to join each circle via line and my final code does it but it has some aligment problems like that:

enter image description here

I marked some joining parts with red circle. They are not properly aligned(line doesn’t out from center of circle) as you see.

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    </head>
    <body>
        <canvas id="graph" width="982" height="636" style="width:491px">
        Tarayıcınız Canvas Desteklemiyor !
        </canvas>

        <script type="text/javascript">
        var i = 0;
        var lastCoord = new Array();
        var c=document.getElementById("graph");
        var cxt=c.getContext("2d");

        function getParam(name)
        {
          name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
          var regexS = "[\\?&]" + name + "=([^&#]*)";
          var regex = new RegExp(regexS);
          var results = regex.exec(window.location.href);
          if(results == null)
            return "";
          else
            return decodeURIComponent(results[1].replace(/\+/g, " "));
        }

        function drawCircleAndLine(x, y)
        {           
            cxt.fillStyle="#000000";
            cxt.beginPath();

            if(i == 0) cxt.arc(x, y, 9, 0, Math.PI*2, false);
            else cxt.arc(x, y, 6, 0, Math.PI*2, false);

            cxt.closePath();
            cxt.fill();

            if(i % 4 != 0)
            {
                cxt.lineWidth = 8;

                cxt.lineTo(lastCoord[0], lastCoord[1]);
                cxt.stroke();
            }
            else {
                cxt.moveTo(lastCoord[0], lastCoord[1]);
                cxt.lineTo(lastCoord[0], lastCoord[1]);
                cxt.stroke();
            }

            lastCoord = [x, y];
            i++;

        }

        var coords = {
            0 : {
                0 : {
                        "0" : { "x" : 50, "y" : 580},
                        "1" : { "x" : 50, "y" : 540},
                        "2" : { "x" : 50, "y" : 472},
                        "3" : { "x" : 50, "y" : 430},
                        "4" : { "x" : 50, "y" : 400},
                        "5" : { "x" : 50, "y" : 382},
                        "6" : { "x" : 50, "y" : 340},
                        "7" : { "x" : 50, "y" : 300},
                        "8" : { "x" : 50, "y" : 250},
                        "9" : { "x" : 50, "y" : 205},
                        "10" : { "x" : 50, "y" : 160},
                        "12" : { "x" : 50, "y" : 138},
                        "14" : { "x" : 50, "y" : 110},
                        "15" : { "x" : 50, "y" : 85},
                        "16" : { "x" : 50, "y" : 65},
                        "20" : { "x" : 50, "y" : 40}
                    },

                1 : {
                        "0" : { "x" : 98, "y" : 555},
                        "1" : { "x" : 98, "y" : 493},
                        "2" : { "x" : 98, "y" : 451},
                        ..............
                        "-4" : { "x" : 926, "y" : 356},
                        "-5" : { "x" : 926, "y" : 375},
                        "-6" : { "x" : 926, "y" : 398},
                        "-7" : { "x" : 926, "y" : 428},
                        "-8" : { "x" : 926, "y" : 452},
                        "-9" : { "x" : 926, "y" : 476},
                        "-10" : { "x" : 926, "y" : 500},
                        "-11" : { "x" : 926, "y" : 530},
                        "-12" : { "x" : 926, "y" : 550},
                        "-16" : { "x" : 926, "y" : 588}
                    }
                }
            };

        var bg = new Image();
        bg.src = "images/disc_graph_empty.jpg";
        bg.onload = function() {
            cxt.drawImage(bg, 0, 0);

            try
            {
                drawCircleAndLine(coords[0][0][getParam('d1')]["x"], coords[0][0][getParam('d1')]["y"]);
                drawCircleAndLine(coords[0][2][getParam('d2')]["x"], coords[0][3][getParam('d2')]["y"]);
                drawCircleAndLine(coords[0][2][getParam('d3')]["x"], coords[0][2][getParam('d3')]["y"]);
                drawCircleAndLine(coords[0][3][getParam('d4')]["x"], coords[0][3][getParam('d4')]["y"]);

                drawCircleAndLine(coords[1][0][getParam('d5')]["x"], coords[1][0][getParam('d5')]["y"]);
                drawCircleAndLine(coords[1][4][getParam('d6')]["x"], coords[1][5][getParam('d6')]["y"]);
                drawCircleAndLine(coords[1][2][getParam('d7')]["x"], coords[1][2][getParam('d7')]["y"]);
                drawCircleAndLine(coords[1][3][getParam('d8')]["x"], coords[1][3][getParam('d8')]["y"]);

                drawCircleAndLine(coords[2][0][getParam('d9')]["x"], coords[2][0][getParam('d9')]["y"]);
                drawCircleAndLine(coords[2][6][getParam('d10')]["x"], coords[2][7][getParam('d10')]["y"]);
                drawCircleAndLine(coords[2][2][getParam('d11')]["x"], coords[2][2][getParam('d11')]["y"]);
                drawCircleAndLine(coords[2][3][getParam('d12')]["x"], coords[2][3][getParam('d12')]["y"]);
            }
            catch(err)
            {
                alert('Hata Oluştu !\nBazı noktalar yerleşmemiş olabilir.\n\n\n' + err);
            }
        }
        </script>

    </body>
</html> 

All files: http://www.2shared.com/file/Uyh2J0Ni/canvas.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-05-25T10:27:08+00:00Added an answer on May 25, 2026 at 10:27 am

    Here is a major simplification of your code that should point out what the problem is. I made the fill light blue and the stroke width smaller so you can see the issue. I am just calling your function twice:

    drawCircleAndLine(100,100);
    drawCircleAndLine(100,200);
    

    You would expect a straight downward line, but clearly it is not going straight! See here:

    http://jsfiddle.net/24khs/

    What is going on is this:

    The first time, just a circle is being drawn with a center at 100,100. This is good

    The second time, a circle is being drawn at 200,200, and then then end of the path at that point is the rightmost part of the circle (which is about 106,200). You are then drawing a line from (106,200) to (100,100).

    In order to fix this, you can add one command, a moveTo(x, y) before your lineTo so that you start the line from the right place. See here:

    http://jsfiddle.net/6VfvG/

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

Sidebar

Related Questions

I'm trying to read a text file (using perl) where each line has several
I'm trying to write some Python code that will traverse each directory in the
I'm trying to do an Outer Join in Symfony. Here's the bit of code
I'm trying to create a named_scope that uses a join, but although the generated
I'm trying to join two table (call them table1 and table2) but only return
I have 5 tables and trying to Join into 1 but I am getting
I'm trying to write a join statement, but am finding that the query I'm
I am trying to replace text in a text file by reading each line,
I'm trying to get these different colors in the table to join each other,
I am trying to join together several audio files into one mp4/m4a file containing

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.