Home Forums Chart Support How can I use PHP MySQL Dynamic data Reply To: How can I use PHP MySQL Dynamic data

#4632

Hi,

I tried to do what you describe here, but my graph is not reloading.. I’m putting the code here:

data.php:
<?php

header(‘Content-Type: application/json’);

//declaracao de servidores
$server = “10.7.5.31”;
$user = “root”;
$senha = “root”;
$bd = “me-rpc”;

mysql_connect($server, $user, $senha) or die(mysql_error());
mysql_select_db($bd) or die(mysql_error());

$data_points = array();

$result1 = mysql_query(“SELECT tamanho, fileName, porcentagem FROM londrina WHERE status = 5 AND origem = ‘curitiba’ AND isLocked = 0 “)
or die(mysql_error());

$result2 = mysql_query(“SELECT tamanho, fileName, porcentagem FROM londrina WHERE status = 5 AND origem = ‘foz’ AND isLocked = 0 “)
or die(mysql_error());

$result3 = mysql_query(“SELECT tamanho, fileName, porcentagem FROM londrina WHERE status = 5 AND origem = ‘cascavel’ AND isLocked = 0 “)
or die(mysql_error());

$result4 = mysql_query(“SELECT tamanho, fileName, porcentagem FROM londrina WHERE status = 5 AND origem = ‘maringa’ AND isLocked = 0 “)
or die(mysql_error());

$result5 = mysql_query(“SELECT tamanho, fileName, porcentagem FROM londrina WHERE status = 5 AND origem = ‘paranavai’ AND isLocked = 0 “)
or die(mysql_error());

$result6 = mysql_query(“SELECT tamanho, fileName, porcentagem FROM londrina WHERE status = 5 AND origem = ‘pontagrossa’ AND isLocked = 0 “)
or die(mysql_error());

$result7 = mysql_query(“SELECT tamanho, fileName, porcentagem FROM londrina WHERE status = 5 AND origem = ‘guarapuava’ AND isLocked = 0 “)
or die(mysql_error());

while($row = mysql_fetch_array( $result1 )) {
if($row[‘fileName’] != null){
$point = array(“label” => $row[‘fileName’] , “y” => ($row[‘porcentagem’]/$row[‘tamanho’]*100));
array_push($data_points, $point);
}else{
$point = array(“label” => “slot livre” , “y” => 0);
array_push($data_points, $point);
}
}

while($row = mysql_fetch_array( $result2 )) {
if($row[‘fileName’] != null){
$point = array(“label” => $row[‘fileName’] , “y” => ($row[‘porcentagem’]/$row[‘tamanho’]*100));
array_push($data_points, $point);
}else{
$point = array(“label” => “slot livre” , “y” => 0);
array_push($data_points, $point);
}
}

while($row = mysql_fetch_array( $result3 )) {
if($row[‘fileName’] != null){
$point = array(“label” => $row[‘fileName’] , “y” => ($row[‘porcentagem’]/$row[‘tamanho’]*100));
array_push($data_points, $point);
}else{
$point = array(“label” => “slot livre” , “y” => 0);
array_push($data_points, $point);
}
}

while($row = mysql_fetch_array( $result4 )) {
if($row[‘fileName’] != null){
$point = array(“label” => $row[‘fileName’] , “y” => ($row[‘porcentagem’]/$row[‘tamanho’]*100));
array_push($data_points, $point);
}else{
$point = array(“label” => “slot livre” , “y” => 0);
array_push($data_points, $point);
}
}

while($row = mysql_fetch_array( $result5 )) {
if($row[‘fileName’] != null){
$point = array(“label” => $row[‘fileName’] , “y” => ($row[‘porcentagem’]/$row[‘tamanho’]*100));
array_push($data_points, $point);
}else{
$point = array(“label” => “slot livre” , “y” => 0);
array_push($data_points, $point);
}
}

while($row = mysql_fetch_array( $result6 )) {
if($row[‘fileName’] != null){
$point = array(“label” => $row[‘fileName’] , “y” => ($row[‘porcentagem’]/$row[‘tamanho’]*100));
array_push($data_points, $point);
}else{
$point = array(“label” => “slot livre” , “y” => 0);
array_push($data_points, $point);
}
}

while($row = mysql_fetch_array( $result7 )) {
if($row[‘fileName’] != null){
$point = array(“label” => $row[‘fileName’] , “y” => ($row[‘porcentagem’]/$row[‘tamanho’]*100));
array_push($data_points, $point);
}else{
$point = array(“label” => “slot livre” , “y” => 0);
array_push($data_points, $point);
}
}

mysql_close();

echo json_encode($data_points, JSON_NUMERIC_CHECK);

?>

graph.html:

<!DOCTYPE html>
<head>

<title>graph</title>

<script src=”jquery.js”></script>

<script src=”canvasjs.js”></script>

<script type=”text/javascript”>
var updateInterval = 100;
var dps;
$(document).ready(function () {

$.getJSON(“data.php”, function (result) {
dps = result;
var chart = new CanvasJS.Chart(“chartContainer”, {
title:{
text: “RECEBIMENTO DE MATERIAIS”,
},
axisY:{
minimum: 0,
maximum: 100
},
data: [

{
type: “stackedBar”,
dataPoints: dps

}

]

});

chart.render();

});

var updateChart = function () {
$.getJSON(“data.php”, function (result) {
dps = result;
});
chart.render();
};

setInterval(function(){updateChart()}, updateInterval);

});

</script>

</head>

<body>

<div id=”chartContainer” style=”height: 300px; width: 100%;”>

</body>

</html>

There´s something wrong? In first time the chart load, but the reload function not.

Thanks

  • This reply was modified 10 years, 10 months ago by teste234@@.