Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/476.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在x秒后刷新画布_Javascript_Php_Ajax_Canvas_Rgraph - Fatal编程技术网

Javascript 如何在x秒后刷新画布

Javascript 如何在x秒后刷新画布,javascript,php,ajax,canvas,rgraph,Javascript,Php,Ajax,Canvas,Rgraph,我希望每x秒刷新一次画布,而不刷新整个页面 <script> $(document).ready(function () { var odo = new RGraph.Odometer({ id: 'cvs', min: 0, max: 360, value: <?php echo $windDirDeg; ?> }).draw(); </script> <body&g

我希望每x秒刷新一次画布,而不刷新整个页面

<script>

$(document).ready(function ()
{
    var odo = new RGraph.Odometer({
        id: 'cvs',
        min: 0,
        max: 360,
        value: <?php echo $windDirDeg; ?>
    }).draw();
 </script>

<body>
 <canvas id="cvs" width="300" height="300"></canvas>
</body>

$(文档).ready(函数()
{
var odo=新的RGraph.里程表({
id:'cvs',
分:0,,
最高:360,
价值:
}).draw();
可能是这样的:

x=3000ms

setInterval(function(){ 
context.clearRect(0, 0, canvas.width, canvas.height);
alert("Canvas cleared"); 
}, 
3000);
完整示例:

<!DOCTYPE html>
<html>
<body>

<canvas id="myCanvas" width="200" height="100" style="border:1px solid #c3c3c3;">
Your browser does not support the HTML5 canvas tag.
</canvas>

<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.fillStyle = "#FF0000";
ctx.fillRect(0,0,150,75);
setInterval(function(){ 
ctx.clearRect(0, 0, c.width, c.height);
alert("Canvas cleared"); 
}, 
3000);
</script>

</body>
</html>

您的浏览器不支持HTML5画布标记。
var c=document.getElementById(“myCanvas”);
var ctx=c.getContext(“2d”);
ctx.fillStyle=“#FF0000”;
ctx.fillRect(0,0150,75);
setInterval(函数(){
ctx.clearRect(0,0,c.宽度,c.高度);
警报(“画布清除”);
}, 
3000);

请参见此

要清除画布,您可以使用RGraph API:

var ca = document.getElementById('cvs');
RGraph.clear(ca, 'white'); // The colour is optional (the default is transparent)

您希望画布中的内容清晰?为什么要使用ajax?我希望在sinhayashuse timeout每x秒刷新一次我的值function@sinhayash任何示例?:)
context.clearRect(0,0,canvas.width,canvas.height);
这是否正常?传递变量c.height。请参阅完整示例$(文档)。就绪(函数(){var odo=new RGraph.Odometer({id:'cvs2',min:0,max:360,value:}).draw();var ctx=odo.getContext(“2d”);setInterval(函数(){ctx.clearRect(0,0,odo.width,odo.height);警报(“画布清除”);},3000;});你是什么意思?你试过这个例子吗?它很好用。你会犯什么错误?