hAxis上的Google图表月

时间:2019-07-09 22:21:10

标签: google-visualization

当我将鼠标悬停在栏上时,我可以弹出日期,但我想分析日期范围内的数据。我看了无数的例子。我搞砸了更改索引并为其创建了一个变量。如果我在数据库中已经有一个datetime变量,那么提交时该如何实现?

<?php

$connect = mysqli_connect("localhost", "root", "password", "administrator_logins");
$query = 'SELECT sum(coins) as CausewayBay, now() AS date FROM cwb_coins';
$result = mysqli_query($connect, $query);
$rows = array();
$table = array();

$table['cols'] = array(
 array(
  'label' => 'date', 
  'type' => 'datetime'
 ),
 array(
  'label' => 'CausewayBay', 
  'type' => 'number'
 )
);

while($row=mysqli_fetch_array($result,MYSQLI_ASSOC)) 
{ 
    echo $row["date"]; 
$sub_array = array(); 
$sub_array[] = array( 
"v" => 'Date(' . $row["date"][0] . ')' 
);  
 $sub_array[] =  array(
      "v" => $row["CausewayBay"]*6
     );
 $rows[] =  array(
     "c" => $sub_array
    );
}
$table['rows'] = $rows;
$jsonTable = json_encode($table);

?>


<html>
 <head>
 <meta http-equiv="refresh" content="30">
  <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
  <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
  <script type="text/javascript">
   google.charts.load('current', {'packages':['corechart']});
   google.charts.setOnLoadCallback(drawChart);
   function drawChart()
   {
    var data = new google.visualization.DataTable(<?php echo $jsonTable; ?>);

    var options = {
     width: 1000, height: 500,
    hAxis: {title: 'Current Time'},
    vAxis: {title: 'Revenue(kWh)', maxValue: 1000, minValue: 0}
    };

    var chart = new google.visualization.ColumnChart(document.getElementById('column_chart'));

    chart.draw(data, options);
   }
  </script>
  <style>
  .page-wrapper
  {
   width:1000px;
   margin:0 auto;
  }
  </style>
 </head>  
 <body>
  <div class="page-wrapper">
   <br />
   <h2 align="center">Rental Revenue</h2>
   <div id="column_chart" style="width: 100%; height: 500px"></div>
  </div>
 </body>
</html>

0 个答案:

没有答案