Kerrop Kerrop - 2 months ago 35
MySQL Question

Highcharts Dynamic update pie Chart mysql

I have an pie and I want to add dynamic update every 3 sec from mysql data.php.I need to add events in .ready(function() ?
Any help would be appreciated.

$(document).ready(function() {
var options = {
chart: {
renderTo: 'container',
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
backgroundColor:'rgba(255, 255, 255, 0.0)'
},
title: {
text: 'Grafic'
},
tooltip: {
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %';
},},
credits: {
enabled: false
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ this.percentage.toFixed(4) +' %';}}}},
series: [{
type: 'pie',
data: []}]}
$.getJSON("data.php", function(json) {
options.series[0].data = json;
chart = new Highcharts.Chart(options);
});
});

Answer

http://www.w3schools.com/js/js_timing.asp

You will probably want to use "setinterval".

You may also need to set up a recursive callback so it updates highcharts every time.

Let me know if you have any questions.

UPDATE 09/29/2016

Here is another way, with a recursive settimeout in jQuery, in case it helps.

(function($){

    $(function(){  //document.ready

    });

    (function recurseEvent(element){

            element.doStuff();

            setTimeout(function(){
                recurseEvent(element);
            }, 2000);

    })($('#myElement'));

})(jQuery);`