I have a controller that queries the data, transforms it into JSON and sends it to the view (which contains the timeline).
The chart you're using is this: link
public function monitor_sala()
{
$data = [];
$reservas = ReservaSala::all();
foreach ($reservas as $reserva) {
$obj = array(
$reserva->nome, $reserva->sala, $reserva->hora_pegar,
$reserva->hora_devolver
);
array_push($data, $obj);
}
return view('salas.monitor', compact('data'));
}
This is the method that sends json (date) to the view ....
In the View the code looks like this:
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script><scripttype="text/javascript">
google.charts.load("current", {packages:["timeline"]});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var container = document.getElementById('example5.1');
var chart = new google.visualization.Timeline(container);
var dataTable = new google.visualization.DataTable();
dataTable.addColumn({ type: 'string', id: 'Room' });
dataTable.addColumn({ type: 'string', id: 'Name' });
dataTable.addColumn({ type: 'date', id: 'Start' });
dataTable.addColumn({ type: 'date', id: 'End' });
dataTable.addRows([
<?php echo json_encode($data) ?>
]);
var options = {
timeline: { colorByRowLabel: true }
};
chart.draw(dataTable, options);
}
</script>
<div id="example5.1" style="height: 100%"></div>
But it does not work, it only picks up when I put the sample data from the documentation. For what it says in the documentation you can use simple numbers to represent the time (so I do not think it's a problem with the format).