简体   繁体   中英

Clear HTML Canvas when new chart is displayed

So I am building an AngularJs chart that utilizes an Angular Library to create the chart on a Canvas tag. However when I drag and drop a new data set onto the canvas to redraw it continues to hold the old data. What I am trying to accomplish is If (there is new data){ clear the canvas}. I know I have to use:

canvasReset.clearRect(0, 0, canvas.width, canvas.height); 

somewhere but what I am really looking for is an event handler to use to assist me in determining if anything is on the canvas, and if so clearing it. However, I am not looking for mouseover mouse-click,etc. But something that is just generally looking to see if the canvas is being utilized.

The short answer, you can't. But you can catch mouseevnets, or you can wrap canvas ctx drawing functions,like

var fill = ctx.fill;
ctx.fill = function(){
    fill.apply(this, arguments);
    setDirty();
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM