All series on a given axis must be of the same data type

匿名 (未验证) 提交于 2019-12-03 01:13:01

问题:

I early had problems with formatting the time, but now having problem with showing the google chart visualiszation out of this error: All series on a given axis must be of the same data type.

This is the goal, with date and time: http://jsbin.com/yaqew/1/edit

As I have been notified the google chart constructor will not accept the time/date string: https://developers.google.com/chart/interactive/docs/reference#dataparam

Database:

PHP:

 'Time', 'type' => 'datetime'),     array('label' => 'Date', 'type' => 'datetime'),     array('label' => 'PH',      'type' => 'number'),     array('label' => 'temperature','type' => 'number'),      array('label' => 'Chlorine','type' => 'number'),     );      $rows = array();      while($r = mysql_fetch_assoc($sth)) {      // assumes dates are in the format "yyyy-MM-dd"     $dateString = $r['Date'];     $dateArray = explode('-', $dateString);     $year = $dateArray[0];     $month = $dateArray[1] - 1; // subtract 1 to convert to javascript's 0-indexed months     $day = $dateArray[2];      echo $dateString."
"; // assumes time is in the format "hh:mm:ss" $timeString = $r['Time']; $timeArray = explode(':', $timeString); $hours = $timeArray[0]; $minutes = $timeArray[1]; $seconds = $timeArray[2]; echo $timeString; $temp = array(); $temp[] = array('v' => "Date($year, $month, $day, $hours, $minutes, $seconds)"); $temp[] = array('v' => (string) $r['PH']); $temp[] = array('v' => (string) $r['temperature']); $temp[] = array('v' => (string) $r['Chlorine']); $rows[] = array('c' => $temp); } $table['rows'] = $rows; $jsonTable = json_encode($table); /* echo $jsonTable; */ ?>

Html/Javascript:

回答1:

Your column definitions are not correct: you want only 1 column for date & time, not two:

$table['cols'] = array(     array('label' => 'Date & Time', 'type' => 'datetime'),     array('label' => 'PH', 'type' => 'number'),     array('label' => 'temperature','type' => 'number'),      array('label' => 'Chlorine','type' => 'number') ); 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!