Move Google Gauge - Javascript Google Chart

Javascript examples for Google Chart:Gauge Chart

Description

Move Google Gauge

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Gauge Chart Example</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> 
      <div id="chart_div" style="width: 400px; height: 120px;"></div> 
      <script type="text/javascript">
      function isEven(n) {/* w  w  w  . j av a 2  s .c  o  m*/
         return n % 2 == 0;// true|false
      }
      google.charts.load('current', {'packages':['gauge']});
      google.charts.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Label', 'Value'],
          ['Memory', 80],
          ['CPU', 55],
          ['Network', 68]
        ]);
        var options = {
          width: 400, height: 120,
          redFrom: 90, redTo: 100,
          yellowFrom:75, yellowTo: 90,
          minorTicks: 5
        };
        var chart = new google.visualization.Gauge(document.getElementById('chart_div'));
        chart.draw(data, options);
        setInterval(function() {
          var chartValue = data.getValue(0, 1);
          if (isEven(chartValue)){
          data.setValue(0, 1, (chartValue + 5));
          } else {
          data.setValue(0, 1, (chartValue - 5));
          }
          chart.draw(data, options);
        }, 450);// milisecond
        setInterval(function() {
          var chartValue = data.getValue(1, 1);
          if (isEven(chartValue)){
          data.setValue(1, 1, (chartValue + 1));
          } else {
          data.setValue(1, 1, (chartValue - 1));
          }
          chart.draw(data, options);
        }, 600);// milisecond
        setInterval(function() {
          var chartValue = data.getValue(2, 1);
          if (isEven(chartValue)){
          data.setValue(2, 1, (chartValue + 3));
          } else {
          data.setValue(2, 1, (chartValue - 3));
          }
          chart.draw(data, options);
        }, 1000);// milisecond
      }

      </script>  
   </body>
</html>

Related Tutorials