简体   繁体   English

显示新图表时清除HTML画布

[英]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. 因此,我正在构建一个利用Angular Library在Canvas标签上创建图表的AngularJs图表。 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}. 我要完成的是If(有新数据){清除画布}。 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 但是您可以捕获mouseevnet,也可以包装canvas ctx绘图函数,例如

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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