Reputation: 447
I am creating an array and I have Dates along with Country (It's coming out of my database). How do I create my AnnotatedTimeLine based off this data? I get the error "First column must contain date, or date and time" with my current set up
Creating Array
while($r = mysqli_fetch_assoc($sth)) {
$callDate = strtotime($r[CALLDATEEST]);
$convertedCallDate = date("Y-m-d",$callDate);
$pieChartArray .= "[$convertedCallDate, '$r[COUNTRY]'],\n";
}
$pieChartArray = substr(trim($pieChartArray), 0, -1);
?>
Function
var data = google.visualization.arrayToDataTable([
['Call times', 'Country'],
<?php echo $pieChartArray; ?>
]);
Upvotes: 0
Views: 254
Reputation: 26340
You need to input the dates as date objects. The easiest way to do that is to use the DataTable JSON structure for your data:
$data = array(
'cols' => array(
array('type' => 'date', 'label' => 'Call times'),
array('type' => 'number', 'label' => 'Country')
),
'rows' => array()
);
while($r = mysqli_fetch_assoc($sth)) {
$callDate = strtotime($r[CALLDATEEST]);
$year = (int) date("Y",$callDate);
$month = ((int) date("m",$callDate)) - 1; // convert months to javascript's 0-indexed months
$day = (int) date("d",$callDate);
$data['rows'][] = array('c' => array(
array('v' => "Date($year, $month, $day)"),
array('v' => $r[COUNTRY])
));
}
then in javascript:
var data = new google.visualization.DataTable(<?php echo json_encode($data, JSON_NUMERIC_CHECK); ?>);
Upvotes: 1