Ajax google visualization API with jquery

I am looking to create a control panel that is updated via ajax. Below is the code that I have. I have ajax code, but I'm not sure how to update the sensor. Any suggestions?

         google.load('visualization', '1', {packages:['gauge']});
          google.setOnLoadCallback(drawChart);
          function drawChart() {
            var data = new google.visualization.DataTable();
            data.addColumn('string', 'Label');
            data.addColumn('number', 'Value');
            data.addRows(1);
            data.setValue(0, 0, 'Tempature');
            data.setValue(0, 1, 76);

            var chart = new google.visualization.Gauge(document.getElementById('liveTempChart'));
            var options = {width: 340, height: 130, redFrom: 90, redTo: 100,
                yellowFrom:75, yellowTo: 90, minorTicks: 5};
            chart.draw(data, options);
          }

ajax code ...

foreach ($ obj-> sensor as $ unit) {if ($ unit-> label == "Temp") {echo $ unit-> tempf. "F"; }}



+3
source share
1 answer

You can also use the same code to update. You need to create a new instance of the data table and call the chart drawing function again (very similar to the way you updated for the first time).

        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Label');
        data.addColumn('number', 'Value');
        data.addRows(1);
        data.setValue(0, 0, 'Tempature');
        data.setValue(0, 1, 76);

        chart.draw(data, options);
+7
source

Source: https://habr.com/ru/post/1758142/


All Articles