如何使Google折线图自动更新,以及添加更多折线和十字线

问题描述 投票:0回答:1

我制作了一个Google折线图,其中应显示从MySQL数据库获取的度量。它显示了它,但是问题是我需要重新加载页面才能出现新的度量。如何使图表每10秒更新一次数据(将数据添加到数据库的时间间隔)。另外,我需要帮助添加多条线并添加一个十字线,该十字线会在鼠标位于图表区域时出现,而不仅是在线本身上。这是我的代码:Linechart.php:

<?php
 $curyear = date('Y');
 $con = mysqli_connect('localhost','u644759843_miki','plantaze2020!','u644759843_plantazeDB');
?>
<html>
  <head>
    <!--Load the AJAX API-->
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">

      // Load the Visualization API and the piechart package.
      google.load('visualization', '1.0', {'packages':['corechart']});

      // Set a callback to run when the Google Visualization API is loaded.
      google.setOnLoadCallback(drawChart);

      // Callback that creates and populates a data table,
      // instantiates the pie chart, passes in the data and
      // draws it.
      function drawChart() {

        // Create the data table.
       var data = google.visualization.arrayToDataTable([
        ['Date', 'Product Purity',],
         <?php 
            $query = "SELECT `FlowRate`, `ProductPurity`, `TimesStamp` FROM `Precizno ProductPurity` WHERE `TimesStamp` >= ( CURDATE() - INTERVAL 3 DAY ) ORDER BY `TimesStamp` DESC";
            $exec = mysqli_query($con,$query);
            while($row = mysqli_fetch_array($exec)){

            date("H:i:s",strtotime($time));
            echo "['".date("H:i", strtotime($row['TimesStamp']))."', ".$row['ProductPurity'].",],";

         }

        ?>

       ]);


        // Set chart options
        var options = {'title':'Nitrogen Generator',
                       'width':1200,
                       'height':300,
                       'crosshair': { trigger: 'both' }
                       // isStacked: true
                       };



        // Instantiate and draw our chart, passing in some options.
        var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
        chart.draw(data, options);



      }
    </script>
  </head>

  <body>
    <!--Divs that will hold the charts-->
    <div id="chart_div"></div>

  </body>
</html>
php html mysql google-visualization linechart
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.