在Google图表中显示Db的日期

时间:2017-09-05 20:42:04

标签: java php mysql json google-visualization

我想在我的Google图表中显示特定日期的月份我有这个JSON(livedata.php)代码:

$data_points = array();
while($row = mysqli_fetch_array($result)){      
$monthNum = date('m',strtotime($row['time_stamp']));
$DayNum = date('d', strtotime($row['time_stamp']));     
$dateObj   = DateTime::createFromFormat('!m', $monthNum);
$monthName = $dateObj->format('F');
if($monthNum == "7"){
      if (array_key_exists($DayNum, $data_points)) {
      $data_points[$DayNum]->ph += $row['ph'];
      $data_points[$DayNum]->moist += $row['moist'];
          }else{
        $data_points[$DayNum]->ts = $DayNum;
      $data_points[$DayNum]->ph = $row['ph'];
      $data_points[$DayNum]->moist = $row['moist'];   
  }
} }
echo json_encode(array_values($data_points));  

显示以下输出:

  

[{" TS":" 29"" pH值":" 8""湿润&#34 ;: #&34; 2"},{" TS":" 28"" pH值" 40"湿润":35 },{" TS":" 27"" pH值":16,"湿润":8}]

上面的输出表示:7月份特定日期的ph值。我想显示ts:月份日但是我的图表没有显示

现在输出图表我有这种javascript代码和图表:

google.charts.load('current', {
    callback: drawChart,
    packages: ['corechart']
    });

 function drawChart() {
     var jsonData = $.ajax({
     url: 'livedata.php',
     dataType: 'json',}).done(function (results) {

     var data = new google.visualization.DataTable();

     data.addColumn('date', 'time_stamp');
     data.addColumn('number', 'ph');
     data.addColumn('number', 'moist');


     $.each(results, function (i, row) {
     var dbdate = new Date();

     data.addRow([
     new Date(dbdate.getFullYear(), dbdate.getMonth(), row.ts),
     parseFloat(row.ph),
     parseFloat(row.moist)]);});

     var chart = new google.visualization.LineChart($('#chart').get(0));

     chart.draw(data, {
     title: 'Soil Analysis'});});
}

输出如下: enter image description here

我想知道为什么它恰好是九月。我想这都是因为我的javascript中的date()。我应该怎么做?请帮助!!我真的是图表和网络方面的新手可视化。我正在寻求帮助。

0 个答案:

没有答案