I have a very simple code that should draw a circle, but its not looking like one, and not at the right position The coordinates are all somewhat shifted. The canvas is set to style="width: 600px; height: 600px;". I tried it on chrome and safari – looks the same so it’s not a browser bug.
So my questions are (there is probably one answer for both):
- If I am putting the center at (100, 100), why is the circle not at an equal distance from the left border, that it is from the top border?
- Why is the (300, 300) point out of the canvas, and not in the center?
The code:
var context = document.getElementById('c').getContext("2d");
context.fillStyle = 'black';
context.fill();
context.beginPath();
context.arc(100, 100, 30, 0, 2 * Math.PI, true);
context.stroke();
How it looks:

Edit
According to the comment I found out that writing <canvas id="myCanvas" style="width: 578px; height: 200px;"></canvas> is causing this problem, and writing <canvas id="myCanvas" width="578" height="200"></canvas> solves it. Anyone knows why?
This is documented in the HTML5 Canvas spec.
The HTML attributes
width="x" height="y"describe the drawing area of the canvas and default to300 × 150 px. As a side-effect, they describe the default visible size of the canvas.The CSS properties
width: x; height: y;set on the canvas can stretch/compact that drawing area, but they don’t change its size.In your case, the browser stretches the default drawing area (
300 × 150 px) to meet the given CSS of600 × 600 px.