0

I am working on a web app and have no idea on how to properly do this, I am already using highstock for static charts, I retrieve temperatures from a Mysql database, and using a PHP class I myself designed I send the data through the use of json to javascript. I know what I trying to do it's possible, there's a jsfiddle example (http://jsfiddle.net/ovhb3jp1/) in highcharts webpage but it graphs only random js generated data.

My guess is I have to make a js script that constantly retrieves the temperatures from a PHP script and sends it to the highstock script that graphs, is that correct? how would i write such a script? I know a lot of PHP and Mysql, but my knowledge of js is pretty vague, so any help would be apreciated.

This is my existing js script

<script>
$(function () {
    $('#container').highcharts('StockChart', <?php echo $chart; ?>);
});
</script>

This is the part of the class that generates the json for the $chart variable

function __toString(){
    $this->datos();
    return json_encode($this->hs);
}

The hs attribute of the class is an array loaded with the parameters of the highstock api, that through the above PHP code is converted into json and put into the above js script.

Thanks!

lucasrod
  • 93
  • 1
  • 12
  • The simples way is prepare PHP script which return only json with data which should be added each time. Next step is catch setInterval (like in the example) and call $.getJSON(), to your php data point. Last step is add value by addPoint. – Sebastian Bochan Apr 27 '15 at 09:34
  • 1
    Just check this [tutorial](http://www.highcharts.com/docs/working-with-data/live-data). Two key-words for you: `AJAX` and `setInterval`/`setTimeout`. – Paweł Fus Apr 27 '15 at 09:35
  • How can I adapt the tutorial for multiple series? Thanks – lucasrod Jun 08 '15 at 15:01

0 Answers0