根据时间戳获取Google图形时出现问题

时间:2018-08-08 07:13:09

标签: javascript php jquery google-visualization

我正在从数据库中获取google graph值,并且能够成功获取各个选项卡。在每小时,每周和每月提取方面,我都面临着这个问题。 问题:列表正在为所有选项卡加载相同的按钮,并且所有值都将出现,而不是特定的选项卡单击值。

如上图所示,氧气选项卡正在显示图形,当我单击氮气时,每小时,每周和每月按钮的值相同。相反,我需要单独使用它。我该如何实现?

alert.php

    <div class="container-fluid">
        <div class="row"> 
            <div class="col-md-12">
                <div class="col-md-6">
                    <br/>
                    <ul class="WinnerButton">      
                        <li role="presentation" class="active">
                            <a href="#Hourly" aria-controls="home" class="btn btn-md WinnerButton" role="tab" onclick="HourlyCardiology()" data-toggle="tab" data-bind="    click: StatisticalHourly">
                                Hourly
                            </a>
                        </li>
                        <li role="presentation">
                            <a href="#Weekly" aria-controls="profile" class="btn btn-md WinnerButton" role="tab" onclick="weeklyCardiology()" data-toggle="tab" data-bind="    click: StatisticalWeekly">
                                WEEKLY
                            </a>
                        </li>
                        <li role="presentation">
                            <a href="#Monthly" aria-controls="messages" class="btn btn-md WinnerButton" role="tab" data-toggle="tab" onclick="monthlyCardiology()" data-bind="click: StatisticalMonthly">
                                MONTHLY
                            </a>
                        </li>
                    </ul>
                    <div id="columnchart_material_chart3" style="width: 400px; height: 300px;"></div>
                </div>
                <div class="col-md-6">
                    <br/>
                    <ul class="WinnerButton">      
                        <li role="presentation" class="active">
                            <a href="#Hourly" aria-controls="home" class="btn btn-md WinnerButton" role="tab" onclick="HourlyGynecology()" data-toggle="tab" data-bind="    click: StatisticalHourly">
                                Hourly
                            </a>
                        </li>
                        <li role="presentation">
                            <a href="#Weekly" aria-controls="profile" class="btn btn-md WinnerButton" role="tab" onclick="weeklyGynecology()" data-toggle="tab" data-bind="    click: StatisticalWeekly">
                                WEEKLY
                            </a>
                        </li>
                        <li role="presentation">
                            <a href="#Monthly" aria-controls="messages" class="btn btn-md WinnerButton" role="tab" data-toggle="tab" onclick="monthlyGynecology()" data-bind="click: StatisticalMonthly">
                               MONTHLY
                            </a>
                        </li>
                    </ul>
                    <div id="columnchart_material_chart4" style="width: 400px; height: 300px;"></div>
                </div>
            </div>
        </div>
    </div>

    function Hourly() {
        var dataday = google.visualization.arrayToDataTable([
            ['Floors','Anesthesia(total)','Anesthesia(used)','Anesthesia(remaining)'],

            <?php 

                $date = strtotime('now') - 3600;  
                $week = strtotime('now') - 604800;  
                $month = strtotime('now') - 2592000 ; 
                $connect = mysqli_connect("localhost", "root", "", "test2"); 

                // Chart 1 ICU co2 for all floors
                $sql1 = "SELECT total,SUM(total) AS sum_sales FROM history WHERE chart_date > DATE_SUB(NOW(), INTERVAL 1 HOUR) AND asset_type = 'Oxygen' AND department='Anesthesia' ";
                $result = mysqli_query($connect, $sql1);  

                $sales_query = $connect->query($sql1);
                $sales_row = $sales_query->fetch_assoc();

                //expense
                $sql1 = "SELECT total,SUM(expenses) AS sum_expenses FROM history WHERE chart_date > DATE_SUB(NOW(), INTERVAL 1 HOUR) AND asset_type = 'Oxygen' AND department='Anesthesia'";
                $expense_query = $connect->query($sql1);
                $expense_row = $expense_query->fetch_assoc();
                $profit = $sales_row['sum_sales'] - $expense_row['sum_expenses'];

                //displaying the needed data
                while($row = mysqli_fetch_assoc($result)) {
                    echo '['.$sales_row['total'].','.$sales_row['sum_sales'].', '.$expense_row['sum_expenses'].', '.$profit.'],';
                }
            ?>
        ]);
        var optionsday = {
            title: 'Hourly'
        };

        var chartday = new google.charts.Bar(document.getElementById('columnchart_material'));

        chartday.draw(dataday,google.charts.Bar.convertOptions(optionsday));
    }

    function HourlyGynecology() {

  var dataday = google.visualization.arrayToDataTable([
            ['Floors','Gynecology(total)','Gynecology(used)','Gynecology(remaining)'],

           <?php 

              $date = strtotime('now') - 3600;  
               $week = strtotime('now') - 604800;  
               $month = strtotime('now') - 2592000 ; 
              $connect = mysqli_connect("localhost", "root", "", "test2"); 

        // Chart 1 ICU co2 for all floors
              $sql1 = "SELECT total,SUM(total) AS sum_sales FROM history WHERE chart_date > 
                  DATE_SUB(NOW(), INTERVAL 1 HOUR) AND asset_type = 'Oxygen' AND department='Gynecology' ";
              $result = mysqli_query($connect, $sql1);  

              $sales_query = $connect->query($sql1);
              $sales_row = $sales_query->fetch_assoc();

              //expense
              $sql1 = "SELECT total,SUM(expenses) AS sum_expenses FROM history WHERE chart_date > 
                  DATE_SUB(NOW(), INTERVAL 1 HOUR) AND asset_type = 'Oxygen' AND department='Gynecology'";
              $expense_query = $connect->query($sql1);
              $expense_row = $expense_query->fetch_assoc();
              $profit = $sales_row['sum_sales'] - $expense_row['sum_expenses'];
              //displaying the needed data

              while($row = mysqli_fetch_assoc($result)) {

                echo '['.$sales_row['total'].','.$sales_row['sum_sales'].', '.$expense_row['sum_expenses'].', '.$profit.'],';
              }
              ?>
]);
   var optionsday = {

          title: 'Hourly'

      };

    var chartday = new google.charts.Bar(document.getElementById('columnchart_material_chart4'));

    chartday.draw(dataday,google.charts.Bar.convertOptions(optionsday));
}

  function weeklyGynecology() {

    var dataweek = google.visualization.arrayToDataTable([
          ['Floors','Gynecology(total)','Gynecology(used)','Gynecology(remaining)'],
           <?php 

               $date = strtotime('now') - 3600;  
               $week = strtotime('now') - 604800;  
               $month = strtotime('now') - 2592000 ;  

              $connect = mysqli_connect("localhost", "root", "", "test2"); 

        // Chart 1  Oxygen for all floors
              $sql1 = "SELECT total,SUM(total) AS sum_sales FROM history WHERE chart_date > 
                  DATE_SUB(NOW(), INTERVAL 1 WEEK) AND asset_type = 'Oxygen' AND department='Gynecology'";
              $result = mysqli_query($connect, $sql1);  

              $sales_query = $connect->query($sql1);
              $sales_row = $sales_query->fetch_assoc();

              //expense
              $sql1 = "SELECT SUM(expenses) AS sum_expenses FROM history WHERE chart_date > 
                  DATE_SUB(NOW(), INTERVAL 1 WEEK) AND asset_type = 'Oxygen' AND department='Gynecology' ";
              $expense_query = $connect->query($sql1);
              $expense_row = $expense_query->fetch_assoc();
              $profit = $sales_row['sum_sales'] - $expense_row['sum_expenses'];
              //displaying the needed data

              while($row = mysqli_fetch_assoc($result)) {

                echo '['.$sales_row['total'].','.$sales_row['sum_sales'].', '.$expense_row['sum_expenses'].', '.$profit.'],';
              }

              ?>
]);







      var optionsweek = {

          title: 'weekly'
      };

      var optionsweek1 = {

          title: 'weekly'
      };



      var chartweek = new google.charts.Bar(document.getElementById('columnchart_material_chart4'));

      chartweek.draw(dataweek, google.charts.Bar.convertOptions(optionsweek));

      var chartweek1 = new google.charts.Bar(document.getElementById('columnchart_material_chart3'));

      chartweek1.draw(dataweek1, google.charts.Bar.convertOptions(optionsweek1));
  }


 // month chart data
  function monthlyGynecology() {

    var datamonth = google.visualization.arrayToDataTable([
          ['Floors','Gynecology(total)','Gynecology(used)','Gynecology(remaining)'],
           <?php 

               $date = strtotime('now') - 3600;  
               $week = strtotime('now') - 604800;  
               $month = strtotime('now') - 2592000 ;  

              $connect = mysqli_connect("localhost", "root", "", "test2"); 

        // Chart 1 ICU co2 for all floors
              $sql1 = "SELECT total,SUM(total) AS sum_sales FROM history WHERE chart_date > 
                  DATE_SUB(NOW(), INTERVAL 1 MONTH) AND asset_type = 'Oxygen' AND department='Gynecology' ";
              $result = mysqli_query($connect, $sql1);  

              $sales_query = $connect->query($sql1);
              $sales_row = $sales_query->fetch_assoc();

              //expense
              $sql1 = "SELECT SUM(expenses) AS sum_expenses FROM history WHERE chart_date > 
                DATE_SUB(NOW(), INTERVAL 1 MONTH) AND asset_type = 'Oxygen' AND department='Gynecology' ";
              $expense_query = $connect->query($sql1);
              $expense_row = $expense_query->fetch_assoc();
              $profit = $sales_row['sum_sales'] - $expense_row['sum_expenses'];
              //displaying the needed data

              while($row = mysqli_fetch_assoc($result)) {

                echo '['.$sales_row['total'].','.$sales_row['sum_sales'].', '.$expense_row['sum_expenses'].', '.$profit.'],';
              }


              ?>
]);

      var optionsmonth = {

          title: 'monthly'

      };

      var chartmonth = new google.charts.Bar(document.getElementById('columnchart_material_chart4'));

      chartmonth.draw(datamonth, google.charts.Bar.convertOptions(optionsmonth));
  }

0 个答案:

没有答案