PHP / JS - Google Graph - 回送数据

时间:2016-10-11 17:33:12

标签: javascript php

我已经查看了与我所问的类似的其他问题但是我们不需要/试图将答案替换为我的代码。

<html>
  <head>
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <script type="text/javascript">
      google.charts.load('current', {'packages':['bar']});
      google.charts.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Stock Price', 'Date'],
          //['2014', 3000],
          <?php
            $DataSearchSQL = "SELECT * FROM stocklog WHERE status = 1 ORDER BY ID DESC LIMIT 7";
            $DataSearchResult = mysqli_query($dbconfig,$DataSearchSQL);
            while($DataSearchRow=mysqli_fetch_array($DataSearchResult,MYSQLI_ASSOC)) {
                $data = $DataSearchRow["StockPrice"];
                $timestamp = $DataSearchRow["Time"];
                $splitTimeStamp = explode(" ",$timestamp);
                $date = $splitTimeStamp[0];
                $info = "['{$date}', {$data}]";
                echo json_encode($info);
            }
            ?>
        ]);

我相信我正在使用$ info和json_encode弄乱一些东西但是我不知道该怎么做,非常感谢帮助。

0 个答案:

没有答案