Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

162
Views
Clear HTML5 canvas with vertical text in Javacript

I'm trying to completely clear a canvas in JavaScript. But if I add a vertical text (rotating the canvas) and then call context.clearRect(0, 0, canvas.width, canvas.height) the text remains. I don't want to use canvas.width = canvas.width or delete the canvas and create a new one.

My code:

var canvas = document.getElementById("canvas");
var c = canvas.getContext("2d");

verticalText("text", 0, 0, 20, "Arial");

c.clearRect(0, 0, canvas.width, canvas.height);
function verticalText(text, x, y, dim, font) {
        c.font = dim + "px " + font;
        var size = c.measureText(text);
        var tx = canvas.width / 2 + dim / 2.5;
        var ty = canvas.height / 2 - dim / 2.5;
        c.save();
        c.translate(tx,ty);
        c.rotate(-Math.PI / 2);
        c.translate(-tx,-ty);
        c.fillText(text, canv.height - y - size.width, x);
        c.restore();
    }

What should I do?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!