4
I’m using the library Rgraph graphics HTML5, and should update dynamically together with the bank.
However, I would like the last data imputed in the bank to be placed on the chart, so if I inserted the value 10 in the bank, the line of the graph would stay at 10 until I insert another value, like 25, and the graph would jump.
But the chart is not making that jump immediately, if the last value is 10, and I inputo 25, it stays at 10 unless I update the page.
Follow the code excerpt:
function update ()
{
// A global
l$.ajax({
type: "POST",
url: "consulta.php",
data: {},
dataType: 'json',
success: function (last)
{
line.originalData[0].push(last);
line.originalData[0].shift();
RGraph.SVG.redraw();
}
});
setTimeout(function () { update() }, 50);
}
update();
Query file.php:
<?php
include("salvateste.php");
$execute_again = mysqli_query($conexao, "Select * FROM tabelapi order by Evento desc");
$lone = mysqli_fetch_object($execute_again);
$mostra_tudao[0] = $lone->Amperes;
echo json_encode($mostra_tudao[0]);
?>
In line line.originalData[0]. push(last); What value goes instead of last?
– Geraldão de Rívia
Actually I had put erradom, fixed the answer already give a look at the update, you return last within Function. changed one word from Function(line) to Function(last).
– AnthraxisBR
I made the changes you suggested, yet nothing happens, now the graph doesn’t plot anything, am I doing something wrong? .php <? php 
include("salvateste.php");
$execute_again = mysqli_query($conexao, "Select * FROM tabelapi order by Evento desc"); 
$lone = mysqli_fetch_object($execute_again); 
$mostra_tudao[0] = $lone->Amperes; 
echo json_encode($mostra_tudao[0]);
?>
– Geraldão de Rívia
Function update: Function update () { // A global l$. ajax({ type: "POST", url: "query.php", data: {}, dataType: 'json', Success: Function (last) { line.originalData[0].push(last); line.originalData[0].shift(); Rgraph.SVG.redraw(); } }); setTimeout(Function () { update() }, 50); } update();
– Geraldão de Rívia
@Feliperodrigues updates the question with the code you are using now formatted, it is very bad to read here in the comment
– AnthraxisBR
I updated it, you can see some error in the code?
– Geraldão de Rívia
From a.log(last) console inside Success:Function(last){} and see if the result is just a number, another observation, you should render the graph with the plugin’s draw function before executing updates: https://www.rgraph.net/demos/svg-line-dynamic.html
– AnthraxisBR
I put the console.log(last) and kept returning me the empty chart, I disabled the other functions and nothing happened, this second thing you told me to do I did not understand very well.
– Geraldão de Rívia
Let’s go continue this discussion in chat.
– AnthraxisBR