/** * Generates the view with statistics for a chosen timeframe. * Includes all persons with LDAP-id set AND status "aktiv" and "kandidat" * OR persons with LDAP-id and other status if they used a schedule in the last 3 month. * * @return int $from * @return int $till * @return RedirectResponse */ public function showStatistics() { // Setting timeframe $from = is_null(Input::get('from')) ? date('Y-m-01') : Input::get('from'); $till = is_null(Input::get('till')) ? date('Y-m-t') : Input::get('till'); // Selecting persons to evaluate $timeSpan = new DateTime("now"); $timeSpan = $timeSpan->sub(DateInterval::createFromDateString('3 months')); $persons = Person::whereRaw("prsn_ldap_id IS NOT NULL \n\t\t\t\t\t\t\t\t\t AND (prsn_status IN ('aktiv', 'kandidat') \n\t\t\t\t\t\t\t\t\t OR updated_at>='" . $timeSpan->format('Y-m-d H:i:s') . "')")->orderBy('prsn_name')->get(); foreach ($persons as $person) { // Define new attribute 'total' for each person object, fill it with the sum received $person->total = $this->countStatisticsById($person->id, $from, $till); } // Generating charts with lavacharts $graphData = Lava::DataTable(); $graphData->addStringColumn('Name')->addNumberColumn('Dienste'); foreach ($persons as $person) { $graphData->addRow(array($person->prsn_name . "(" . substr($person->prsn_status, 0, 1) . ")" . "(" . $person->getClub->clb_title . ")", $person->total)); } $columnchart = Lava::ColumnChart('Dienste')->setOptions(array('datatable' => $graphData)); return View::make('statisticsView', compact('persons', 'from', 'till')); }
/** * @return mixed */ public function reportIniciativaInstituicao(Request $request = null) { if ($request != null) { switch ($request['type']) { case 'geral': return $this->reportIniciativaInstituicaoGeral()->toJson(); break; case 'regiao': switch ($request['regiao']) { case 1: return $this->reportIniciativaInstituicaoByUf([50, 51, 52, 53])->toJson(); break; case 2: return $this->reportIniciativaInstituicaoByUf([11, 12, 13, 14, 15, 16, 17])->toJson(); break; case 3: return $this->reportIniciativaInstituicaoByUf([21, 22, 23, 24, 25, 26, 27, 28, 29])->toJson(); break; case 4: return $this->reportIniciativaInstituicaoByUf([41, 42, 43])->toJson(); break; case 5: return $this->reportIniciativaInstituicaoByUf([31, 32, 33, 35])->toJson(); break; } break; case 'estado': if ($request['cidade'] != '') { return $this->reportIniciativaInstituicaoByCidade($request['cidade'])->toJson(); } else { return $this->reportIniciativaInstituicaoByUf([$request['uf']])->toJson(); } break; } } else { $dados = $this->reportIniciativaInstituicaoGeral(); $graph = \Lava::ColumnChart('IniciativaInstituicao')->setOptions(['datatable' => $dados, 'legend' => \Lava::Legend(['position' => 'top'])]); return $graph; } }
/** * @param string $name * @param string $title * @param bool|false $isStacked */ public function getColumnChart($name = '', $title = '', $isStacked = false) { $this->columnChart = \Lava::ColumnChart($name, $this->lavaDataTable, ['isStacked' => $isStacked]); $this->setTitle($title); }
<?php $links = Residencias::paginate(15); $residencias = $links->lists('nombre', 'id'); // dd($residencias); $stocksTable = Lava::DataTable(); $stocksTable->addStringColumn('Cantidad de Personas')->addNumberColumn('Cantidad', null, '#FFFFFF'); foreach ($residencias as $id => $residencia) { $rowData = array($residencia, Residencias::find($id)->personas()->count()); $stocksTable->addRow($rowData); } $chart = Lava::ColumnChart('CantidadChart')->title('Grafico de Habitat Por Residencia')->colors(array('yellow')); $chart->datatable($stocksTable); ?> <div class="col-md-12"> <h3 class="text-success text-center">Cantidad de Usuarios Por Residencia</h3> {{ Lava:: render('ColumnChart', 'CantidadChart', 'CantidadChart', true);}} <div class="col-md-9 col-md-offset-3"> {{$links->links();}} </div> </div>
public function createColumnChart($UnitIds, $ChartTable) { $dataTable = $this->dataTableFiller($UnitIds, $ChartTable); $columnchart = \Lava::ColumnChart('ColumnChart')->dataTable($dataTable)->title('Column'); }
<div class="well well-lg col-md-12"> <h4>Planes mas Visitados</h4> <?php use Carbon\Carbon; $stocksTable = Lava::DataTable(); $planes = App\Planes::all()->toArray(); $stocksTable->addStringColumn('Usuarios Activos')->addNumberColumn('Cantidad de Visitas en el mes'); foreach ($planes as $key => $plan) { $rowData = array($plan["nombre"], rand(50, 100)); $stocksTable->addRow($rowData); } $lineChart = Lava::ColumnChart('Stocks')->setOptions(array('datatable' => $stocksTable)); echo Lava::render('ColumnChart', 'Stocks', 'planes-div', true); ?> </div>
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $stocksTable = \Lava::DataTable(); // Lava::DataTable() if using Laravel $stocksTable->addColumns(array(array('string', 'Date'), array('number', 'On'), array('number', 'Off'))); $sql = "select TIME(created_at) as createdat,\n \n COUNT(IF(sensor_state=1, 1, NULL)) AS on_state,\n COUNT(IF(sensor_state=0, 1, NULL)) AS off_state\n FROM smoke_sensors GROUP BY created_at"; //$sql="select count(sensor_state) as count_val,TIME(created_at) as createdat from smoke_sensors // group by createdat "; $result = DB::select($sql); foreach ($result as $data) { $rowData = array($data->createdat, $data->on_state, $data->off_state); $stocksTable->addRow($rowData); } /*for ($a = 1; $a < 30; $a++) { $rowData = array( "2014-8-$a", rand(800,1000), rand(800,1000) ); $stocksTable->addRow($rowData); }*/ $lineChart = \Lava::ColumnChart('Stocks')->setOptions(array('datatable' => $stocksTable, 'title' => 'Smoke Sensor States')); //$chart->datatable($stocksTable); return View('Home.charts'); }