I'm trying to develop a div that is automatically updated with your own content as it will be to show a real ping a website on canvas.
I have the following script:
<script>
var auto_refresh = setInterval(
function()
{
$('#divcanvas').fadeOut('slow').load('teste.php #divcanvas').fadeIn("slow");
}, 1000);
</script>
In my markup have:
<div style="width:30%">
<div id="divcanvas">
<canvas id="canvas" height="450" width="600"></canvas>
</div>
</div>
And in test.php have:
<?php
include_once "ping/pingdomain.php";
require_once "ping/config.php";
$ms = pingDomain('www.adhenrique.com.br');
$hora = date("H:i:s", time());
mysql_query("insert into ping (resposta, horario) values ('$ms', '$hora')");
$sql = mysql_query("SELECT * FROM PING order by id DESC LIMIT 0,15");
?>
<head>
<title>Documento sem título</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="includes/js/chart.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
<canvas id="canvas" height="450" width="600"></canvas>
<?php
$pingreposta = array();
$pinghorario = array();
while($valor = mysql_fetch_assoc($sql))
{
extract($valor);
$pinghorario[] = $valor['horario'];
$pingreposta[] = $valor['resposta'];
}
?>
<script>
var lineChartData = {
labels :<?php echo '[' .'"'. implode('","', $pinghorario) .'"'. ']'; ?>
,
datasets : [
{
label: "My First dataset",
fillColor : "rgba(220,220,220,0.2)",
strokeColor : "rgba(220,220,220,1)",
pointColor : "rgba(220,220,220,1)",
pointStrokeColor : "#fff",
pointHighlightFill : "#fff",
pointHighlightStroke : "rgba(220,220,220,1)",
data : <?php echo '[' . implode(',', $pingreposta) . ']'; ?>
}
]
}
window.onload = function(){
var ctx = document.getElementById("canvas").getContext("2d");
window.myLine = new Chart(ctx).Line(lineChartData, {
responsive: true
});
}
</script>
</body>
</html>
But when i open the index.php, it does not show the canvas. But if i open the test.php data it shows. That is, the code of canvas is correct.
Where is my mistake?