-1
I have a controller that queries the data, transforms it into JSON and sends it to the view (which contains Timeline).
The chart being used is this: https://developers.google.com/chart/interactive/docs/gallery/timeline#Controlling-the-Colors
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 View the code is like this :
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="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 doesn’t work, it only picks up when I put the sample data in the documentation. From what it says in the documentation you can use simple numbers to represent the time (so I guess it’s no problem with the format).
Avoid placing images, paste the codes. When someone will help you the first thing they will do is copy the code and test. With pictures no one will do that
– Pedro Augusto
Hello friend! Just edit your question. Edit and replace the images with the code.
– Fabiano Monteiro
Okay, I’ve already put the code in place of the images
– Jilcimar Fernandes