Datasets line chart #8340
Unanswered
RedyDelgado
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
hi, thanks in advance. How can I modify my code to have "n" line graphs according to my users. I leave my code that works fine, but for a single user.
<script> var config = { type: "line", data: { labels: [], datasets: [{ label: [], data: [], fill: false, borderColor: "rgb(75, 192, 192)", lineTension: 0.1, }] }, options: {} }; window.onload = function() { var datos = <?php echo json_encode($t_reg_x_usuario) ?>; var totaldias = datos.totaldias; var registrosdia = datos.registros_x_dia; var i = 0; for (i = 1; i <= totaldias; i++) { config.data.datasets[0].data.push(registrosdia[i]); config.data.labels.push(i); } var ctx = document.getElementById('chartjs').getContext('2d'); window.myLine = new Chart(ctx, config); }; </script>
in el conponent
$primer_dia = 1; $ultimo_dia = $this->getUltimoDiaMes($anio, $mes); $fecha_inicial = date("Y-m-d H:i:s", strtotime($anio . "-" . $mes . "-" . $primer_dia)); $fecha_final = date("Y-m-d H:i:s", strtotime($anio . "-" . $mes . "-" . $ultimo_dia)); $registros_tickets_usuario = Ticket::whereBetween('created_at', [$fecha_inicial, $fecha_final])->get(); $usuario = user::all(); for ($d = 1; $d <= $ultimo_dia; $d++) { $registros[$d] = 0; } foreach ($registros_tickets_usuario as $registros_x_usuario) { $diasel = intval(date("d", strtotime($registros_x_usuario->created_at))); $registros[$diasel]++; } $t_reg_x_usuario = array("totaldias" => $ultimo_dia, "registros_x_dia" => $registros); return view('dashboard.dashboard-component', compact('t_reg_x_usuario'));
Beta Was this translation helpful? Give feedback.
All reactions