Home > Web Front-end > HTML Tutorial > How to clear a chart on HTML5 canvas to prevent hover events from being triggered?

How to clear a chart on HTML5 canvas to prevent hover events from being triggered?

PHPz
Release: 2023-08-20 20:41:19
forward
1457 people have browsed it

How to clear a chart on HTML5 canvas to prevent hover events from being triggered?

To clear the chart from the canvas, delete the element and append a new element to the parent container, as shown below Code:

var resetCanvas = function(){
   $('#results-graph').remove();  
   $(&#39;#graph-container&#39;).append(&#39;<canvas id = "results-graph"><canvas>&#39;);
   canvas = document.querySelector(&#39;#results-graph&#39;);

   ct = canvas.getContext(&#39;2d&#39;);
   ct.canvas.width = $(&#39;#graph&#39;).width(); // here we are resizing the new canvas element to parent width
   ct.canvas.height = $(&#39;#graph&#39;).height(); // here we are resizing the new canvas element to parent height
   var a = canvas.width/2;
   var b = canvas.height/2;

   ct.font = &#39;12pt Calibri&#39;;
   ct.textAlign = &#39;Align Left&#39;;
   ct.fillText(&#39;left aligned text on the canvas&#39;, a, b);
};
Copy after login

The above is the detailed content of How to clear a chart on HTML5 canvas to prevent hover events from being triggered?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template