Füllen einer Leinwandform mit Text

Ich versuche herauszufinden, wie man einen Text zu einer Leinwandform hinzufügtCode:

<code>var text ="5"; // text to display over the circle
context.fillStyle = "red";
context.beginPath();
context.arc(50,70, 10, 0, Math.PI * 2);
context.closePath();
context.fill(); 
</code>

Ich würde es sehr begrüßen, wenn mir jemand helfen würde, den Text der Form im Voraus hinzuzufügen.

BEARBEITEN Ich finde heraus, dass ich noch einmal auf die Leinwand schreiben muss, also ist es das, was ich bisher bekommen habe ... aber der Text ist nicht auf die Mitte des Kreises ausgerichtet:

<code>  context.fillStyle = "red";
  context.beginPath();
  var radius = 10; // for example
  context.arc(200, 200, radius, 0, Math.PI * 2);
  context.closePath();
  context.fill();
  context.fillStyle = "black"; // font color to write the text with
  var font = "bold " + radius +"px serif";
  context.font = font;
  context.textBaseline = "top";
  context.fillText(text, 200-radius/4 ,200-radius/2);
</code>

Antworten auf die Frage(1)

Ihre Antwort auf die Frage