I am trying to figure out how to add text to the canvas form for example, here is my code :
var text ="5";
context.fillStyle = "red";
context.beginPath();
context.arc(50,70, 10, 0, Math.PI * 2);
context.closePath();
context.fill();
I would really appriciate it if someone helped me add text to the form thanks in advance.
EDIT
I understand that I need to write on the canvas again, so this is what I got so far ... but the text does not snap to the center of the circle:
context.fillStyle = "red";
context.beginPath();
var radius = 10;
context.arc(200, 200, radius, 0, Math.PI * 2);
context.closePath();
context.fill();
context.fillStyle = "black";
var font = "bold " + radius +"px serif";
context.font = font;
context.textBaseline = "top";
context.fillText(text, 200-radius/4 ,200-radius/2);
source
share