public function findForPage($page_id) { $data = self::findBy(['page' => $page_id]); $ret = []; foreach ($data as $element) { $id = $element->getId(); $backgroundColor = self::hex2rgba($element->getBackgroundColor(), $element->getBackgroundOpacity()); $chart = new Highchart(); $chart->global->useUTC(false); $chart->chart->animation(false)->renderTo('chart_' . $id)->backgroundColor($backgroundColor)->height($element->getHeight())->margin([2, 2, 2, 2]); $chart->title->text(null); $chart->xAxis->title(null)->type('datetime')->visible(false); $chart->yAxis->title(null)->visible(true)->minorTickColor('transparent')->minorGridLineColor('transparent')->gridLineColor('transparent')->lineColor('transparent')->plotLines([['value' => $element->getConst(), 'color' => $element->getConstColor(), 'width' => 1]]); $chart->exporting->enabled(false); $chart->legend->enabled(false); $chart->credits->enabled(false); $chart->tooltip->enabled(false); $chart->plotOptions->series(['lineWidth' => 1, 'marker' => ['enabled' => false], 'enableMouseTracking' => false]); $from = (new \DateTime())->modify("-" . $element->getHourOffset() . " hour"); $registerArchiveData = self::getArchiveData($from, $element->getSource()->getId()); $arrayToChart = array(); foreach ($registerArchiveData as $rad) { $time = $rad["timeOfInsert"]->getTimestamp() * 1000; array_push($arrayToChart, [$time, $rad["fixedValue"]]); } $series = ['data' => $arrayToChart, 'color' => $element->getColor()]; $chart->series([$series]); $ret[$id] = $chart; } return $ret; }
public function chartAction($pk) { $Project = $this->getObject($pk); $this->checkCredentials($Project); if (!$Project) { throw new NotFoundHttpException("The Taskeet\\MainBundle\\Entity\\Project with id {$pk} can't be found"); } $ob = new Highchart(); $ob->chart->renderTo($Project->getName()); $ob->title->text($Project->getName()); $ob->plotOptions->pie(array('allowPointSelect' => true, 'cursor' => 'pointer', 'dataLabels' => array('enabled' => false), 'showInLegend' => true)); $data = array(); $datag = array(); foreach ($Project->getTickets() as $task) { if (array_key_exists($task->getStatus()->getName(), $data)) { $data[$task->getStatus()->getName()] = $data[$task->getStatus()->getName()] + 1; } else { $data[$task->getStatus()->getName()] = +1; } } foreach ($data as $key => $value) { $datag[] = array($key, $value); } $ob->series(array(array('type' => 'pie', 'name' => 'Estado de las tareas', 'data' => $datag))); return $this->render('TaskeetMainBundle:ProjectShow:chart.html.twig', $this->getAdditionalRenderParameters($Project) + array("Project" => $Project, 'chart' => $ob)); }
/** * Series output */ public function testData() { $chart = new Highchart(); $chart->series($this->series); $this->assertRegExp('/\\{"name":"Data Serie #1","data":\\[1,2,4,5,6,3,8\\]\\}/', $chart->render()); $this->assertRegExp('/\\{"name":"Data Serie #2","data":\\[7,3,5,1,6,5,9\\]\\}/', $chart->render()); }
public function PieAction() { $ob = new Highchart(); $ob->chart->renderTo('piechart'); $ob->title->text('Nombre des utilisateurs '); $ob->plotOptions->pie(array('allowPointSelect' => true, 'cursor' => 'pointer', 'dataLabels' => array('enabled' => false), 'showInLegend' => true)); $em = $this->getDoctrine()->getManager(); $query = $em->createQuery('SELECT count(et.id) FROM MyAppGrapheBundle:Administrateur et'); $Administrateur = $query->getSingleScalarResult(); $et = (int) $Administrateur; $em1 = $this->getDoctrine()->getManager(); $query1 = $em1->createQuery('SELECT count(en.sexe) FROM MyAppGrapheBundle:Client en'); $Client = $query1->getSingleScalarResult(); $en = (int) $Client; $em3 = $this->getDoctrine()->getManager(); $query3 = $em3->createQuery('SELECT count(en2.nbreboutique) FROM MyAppGrapheBundle:Mall en2'); $Mall = $query3->getSingleScalarResult(); $en2 = (int) $Mall; $em4 = $this->getDoctrine()->getManager(); $query4 = $em4->createQuery('SELECT count(en3.nbreenseigne) FROM MyAppGrapheBundle:Mall en3'); $mall = $query4->getSingleScalarResult(); $en3 = (int) $mall; $data = array(array('Administrateur', $et), array('Client', $en), array('Mall', $en2), array('Mall', $en3)); $ob->series(array(array('type' => 'pie', 'name' => 'Browser share', 'data' => $data))); return $this->render('MyAppGrapheBundle:Graphe:pie.html.twig', array('chart' => $ob)); }
/** * @Route("/stationstate/{stationId}", requirements={"stationId"="\d+"}, name="station_state_graph") * @Method("GET") * @Template() */ public function chartAction($stationId) { $stationRepository = $this->getDoctrine()->getRepository('StationMapping:Station'); /** * @var Station $station */ $station = $stationRepository->findOneById($stationId); $startingTime = time() - 86400; $availableBikes = []; foreach ($station->getStationStates() as $stationState) { $stationStateTime = $stationState->getTime()->getTimestamp(); if ($stationStateTime >= $startingTime) { // this needs to be optimized $relativeTimeOfTheDayInHours = ($stationStateTime - $startingTime) / 3600; // this is not really the relative time of the day, need to calculate properly $availableBikes[] = [$relativeTimeOfTheDayInHours, $stationState->getAvailableBikes()]; } } $availableBikes[] = [(time() - $startingTime) / 3600, $station->getCurrentStationState()->getAvailableBikes()]; $series = array(array("name" => sprintf('Available bikes for %d', $stationId), 'data' => $availableBikes)); $chart = new Highchart(); $chart->chart->renderTo('linechart'); // The #id of the div where to render the chart $chart->title->text('Chart Title'); $chart->xAxis->title(array('text' => "Horizontal axis title")); $chart->yAxis->title(array('text' => "Vertical axis title")); $chart->series($series); return array('chart' => $chart); }
/** * @Route("", name="landing") * @Template("ReportsBundle:Default:index.html.twig") */ public function indexAction() { $data = array(); $bigDataArray = array(); $closedTickets = $this->get('doctrine')->getEntityManager('ost')->createQuery("SELECT ostt FROM ReportsBundle:ost_ticket ostt WHERE ostt.statusid = 2 or ostt.statusid = 3")->getResult(); $num = count($closedTickets); $data['total_closed_tickets'] = $num; $query = $this->get('doctrine')->getEntityManager('ost')->createQuery("SELECT ostt FROM ReportsBundle:ost_ticket ostt WHERE ostt.statusid = 1")->getResult(); $num = count($query); $data['total_open_tickets'] = $num; //Grab start date $startDateInSeries = $closedTickets[0]->getClosed(); // Grab last date $endDateInSeries = $closedTickets[$data['total_closed_tickets'] - 1]->getClosed(); $yourController = $this->get('adminService'); $bigDataArray = $yourController->__getTimeSeriesFromDates($startDateInSeries, $endDateInSeries, $closedTickets); $series = array(array("name" => "Data Series Name", "data" => $bigDataArray, "type" => "area")); $func = new Expr('function(e) { var id = $("#linechart").attr("data-id"); $.ajax({ type: "POST", url: "/ticketlookup", data: { id: id, startDate: e.min, endDate: e.max, }, dataType: "json", success: function(response) { $("#response").children().remove(); if(response.total_response != 0) { $("#response").append("<p>Total number of tickets: "+response.total_response); $("#response").append(response.table); } } }); }'); $ob = new Highchart(); $ob->chart->renderTo('linechart'); // The #id of the div where to render the chart $ob->chart->zoomType('x'); $ob->legend->enabled(false); $ob->title->text('Timeseries of closed tickets'); $ob->xAxis->title(array('text' => "Dates")); $ob->xAxis->events(array('setExtremes' => $func)); $ob->xAxis->type('datetime'); //$ob->xAxis->tickInterval((24 * 3600 * 1000 * 10)); $ob->yAxis->title(array('text' => "Freq of closed tickets")); $ob->yAxis->type(array('number')); $ob->plotOptions->line(array('dataLabels' => array('enabled' => true))); $ob->series($series); return array('data' => $data, 'chart' => $ob); }
public function newPieChart($series) { $ob = new Highchart(); $ob->plotOptions->pie(array('allowPointSelect' => true, 'cursor' => 'pointer', 'showInLegend' => true, 'dataLabels' => array('enabled' => false))); $ob->series($series); $ob->title->style(array('fontWeight' => 'bold', 'fontSize' => '20px')); $ob->credits->enabled(false); $ob->title->text('Répartition des dépenses selon les comptes comptables (Mandat en cours)'); $ob->tooltip->pointFormat('{point.percentage:.1f} %'); return $ob; }
public function getChart() { $ob = new Highchart(); $ob->chart->renderTo('linechart'); $ob->title->text('History data for your portfolio'); $ob->xAxis->title(['text' => "Time"]); $ob->xAxis->categories($this->xAxisPoints); $ob->yAxis->title(['text' => "Price"]); $ob->series($this->series); return $ob; }
public function createConfiguration(array $addedVocabularyData, array $learnedVocabularyData, Date $startDate, $chartId) { $series = array(array('name' => 'Added vocabulary', 'data' => $addedVocabularyData, 'color' => '#5D6FE3', 'pointStart' => new Expr('Date.UTC(' . $startDate->getYear() . ', ' . $startDate->getMonth() . ', ' . $startDate->getDay() . ')'), 'pointInterval' => new Expr('24 * 3600 * 1000')), array('name' => 'Learned vocabulary', 'data' => $learnedVocabularyData, 'color' => '#5DB83D', 'pointStart' => new Expr('Date.UTC(' . $startDate->getYear() . ', ' . $startDate->getMonth() . ', ' . $startDate->getDay() . ')'), 'pointInterval' => new Expr('24 * 3600 * 1000'))); $ob = new Highchart(); $ob->chart->renderTo($chartId); $ob->title->text('Vocabulary'); $ob->xAxis->type('datetime'); $ob->exporting->enabled(false); $ob->series($series); return $ob; }
public function indexAction() { // Chart $series = array(array("name" => "Data Serie Name", "data" => array(1, 2, 4, 5, 6, 3, 8))); $ob = new Highchart(); $ob->chart->renderTo('linechart'); // The #id of the div where to render the chart $ob->title->text('Chart Title'); $ob->xAxis->title(array('text' => "Horizontal axis title")); $ob->yAxis->title(array('text' => "Vertical axis title")); $ob->series($series); return $this->render('test.html.twig', array('chart' => $ob)); }
/** * @param string $command * @param string $category * @param array $logs * * @return Highchart */ public static function get($command, $category, array $logs) { $series = array(array("name" => sprintf("%s - %s statistics", $command, ucfirst($category)), "data" => array_values($logs))); $ob = new Highchart(); $ob->chart->renderTo('linechart'); // The #id of the div where to render the chart $ob->title->text('Chart Title'); $ob->xAxis->title(array('text' => "Date and time")); $ob->xAxis->categories(array_keys($logs)); $ob->yAxis->title(array('text' => sprintf("%s (in %s)", ucfirst($category), Parser::getCategoryUnit($category)))); $ob->series($series); return $ob; }
public function chartAction() { // Chart $series = array(array("name" => "Data Serie Name", "data" => array(1, 2, 4, 5, 6, 3, 8))); $ob = new Highchart(); $ob->chart->renderTo('linechart'); // The #id of the div where to render the chart $ob->title->text('nombre d utilisateur connecte'); $ob->xAxis->title(array('text' => "date")); $ob->yAxis->title(array('text' => "utilisateur Connecte")); $ob->series($series); return $this->render('utilisateurBundle:Default:statistique.html.twig', array('chart' => $ob)); }
public function buildChart($data) { $series = [['name' => 'Total tasks', 'data' => [$data['all']]], ['name' => 'Completed', 'data' => [$data['completed']]], ['name' => 'Completed on-time', 'data' => [$data['completed_ontime']]], ['name' => 'Completed overdue', 'data' => [$data['completed_overdue']]], ['name' => 'Pending', 'data' => [$data['pending']]], ['name' => 'Pending on-time', 'data' => [$data['pending_ontime']]], ['name' => 'Pending overdue', 'data' => [$data['pending_overdue']]]]; $ob = new Highchart(); $ob->chart->renderTo('stat-charts'); // The #id of the div where to render the chart $ob->chart->type('column'); $ob->title->text('Task Statistics'); $ob->xAxis->title(['text' => "Parameter"]); $ob->yAxis->title(['text' => "Value"]); $ob->series($series); return $ob; }
/** * @Route("/", name="dashboard") * @Template() */ public function indexAction() { $linechart = new Widget('Line Chart', 'linechart'); $series = array(array("name" => "Data Serie Name", "data" => array(1, 2, 4, 5, 6, 3, 8))); $ob = new Highchart(); $ob->chart->renderTo('linechart'); // The #id of the div where to render the chart $ob->title->text('Chart Title'); $ob->xAxis->title(array('text' => "Horizontal axis title")); $ob->yAxis->title(array('text' => "Vertical axis title")); $ob->series($series); $linechart->setChartData($ob); $widgets = array($linechart); return array("widgets" => $widgets); }
public function execute(BlockContextInterface $block, Response $response = null) { // merge settings $settings = array_merge($this->getDefaultSettings(), $block->getSettings()); // Get validated hours per week $query = $this->em->createQuery("SELECT\n SUM(HOUR(c.duration) + MINUTE(c.duration)/60) AS time,\n YEAR(c.date) AS year,\n WEEK(c.date) AS week\n FROM MathsupCouponBundle:Course c\n GROUP BY year, week\n ORDER BY year, week DESC\n "); $hoursPerWeek = $query->getArrayResult(); $hoursPerWeekData = []; foreach ($hoursPerWeek as $week) { $week_start = new \DateTime(); $week_start->setISODate($week['year'], $week['week']); $hoursPerWeekData[] = array('name' => $week_start->format('d-M-Y'), 'x' => $week_start->getTimestamp() * 1000, 'y' => (int) $week['time']); } $query = $this->em->createQuery("\n SELECT\n COUNT(s) AS n,\n YEAR(s.createdAt) AS year,\n MONTH(s.createdAt) AS month,\n DAY(s.createdAt) AS day,\n s.createdAt AS date\n FROM MathsupUserBundle:Student s\n GROUP BY year, month, day\n ORDER BY s.createdAt ASC\n "); $studentCountEvolution = $query->getResult(); $studentCountEvolutionData = []; $studentCount = 0; foreach ($studentCountEvolution as $day) { $studentCount += $day['n']; $studentCountEvolutionData[] = array('name' => $day['date']->format('d-M-Y'), 'y' => (int) $studentCount, 'x' => $day['date']->getTimestamp() * 1000); } $hoursPerWeekChart = new Highchart(); $hoursPerWeekChart->title->text('Heures de cours validées par semaine'); $hoursPerWeekChart->chart->renderTo('hours_per_week_chart'); $hoursPerWeekChart->chart->zoomType('x'); $hoursPerWeekChart->xAxis->title(array('text' => "Semaine")); $hoursPerWeekChart->xAxis->type('datetime'); $hoursPerWeekChart->yAxis(array(array("title" => array('text' => "Heures")), array("title" => array('text' => "Nombre d'étudiants"), "opposite" => true))); $series = array(array("name" => "Nombre d'heure", "type" => "column", "data" => $hoursPerWeekData), array("name" => "Nombre d'étudiants", "data" => $studentCountEvolutionData, "step" => true, "yAxis" => 1)); $hoursPerWeekChart->series($series); $qb = $this->em->createQueryBuilder(); $qb->select($qb->expr()->count('s'))->from('MathsupUserBundle:Student', 's')->where('s.enabled = true'); $studentCount = $qb->getQuery()->getSingleScalarResult(); // get professor count $qb = $this->em->createQueryBuilder(); $qb->select($qb->expr()->count('p'))->from('MathsupUserBundle:Professor', 'p')->where('p.enabled = true'); $professorCount = $qb->getQuery()->getSingleScalarResult(); // Create user number (and repartition) pie chart $usersChart = new Highchart(); $usersChart->title->text('Utilisateurs'); $usersChart->chart->renderTo('users_chart'); $usersChart->chart->type('pie'); $usersChart->plotOptions->pie(array('allowPointSelect' => true, 'cursor' => 'pointer', 'dataLabels' => array('enabled' => true, 'format' => '<b>{point.name}</b>: {point.y}'))); $usersChart->series(array(array('name' => 'Utilisateurs', 'colorByPoint' => 'true', 'data' => array(array('name' => 'Étudiants', 'y' => (int) $studentCount), array('name' => 'Professeurs', 'y' => (int) $professorCount))))); return $this->renderResponse($block->getTemplate(), array('hours_per_week_chart' => $hoursPerWeekChart, 'student_count_evolution' => $studentCountEvolutionData, 'users_chart' => $usersChart, 'block' => $block->getBlock(), 'settings' => $settings), $response); }
public function getSimplyCharts(Session $session, $questions) { $charts = array(); foreach ($questions as $question) { $chartName = 'questionChart' . $question->getId(); $answers = $this->manager->getRepository('SurveyBundle:Answer')->findBy(array('session' => $session, 'question' => $question)); $series = array(array('type' => 'column', "name" => 'Votes', "data" => $this->getSerieData($question, $answers))); $ob = new Highchart(); $ob->chart->renderTo($chartName); // The #id of the div where to render the chart $ob->title->text($question->getTitle()); $ob->xAxis->title(array('text' => $question->getScale()->getLeftLabel() . ' - ' . $question->getScale()->getRightLabel())); $ob->xAxis->categories(array_fill(0, $question->getScale()->getSize(), '')); $ob->series($series); $charts[$chartName] = $ob; } return $charts; }
/** * @Route("/{cid}ver/{caid}") * @Template() */ public function verAction($cid, $caid) { $em = $this->getDoctrine()->getManager(); $carrera = $em->getRepository('UmgVotacionBundle:CampusCarrera')->find($caid); $catedratico = $em->getRepository('UmgVotacionBundle:Catedratico')->find($cid); $cursos = $em->getRepository('UmgVotacionBundle:CarreraCurso')->findCursos($carrera, $catedratico); $promedio = $em->getRepository('UmgVotacionBundle:CampusCarrera')->findPunteoCatedraticoCarrera($catedratico, $carrera); $datos = array(); foreach ($promedio as $prom) { $datos[] = floatval($prom['calificacion']); } $series = array(array("name" => "Data Serie Name", "data" => $datos)); $ob = new Highchart(); $ob->chart->renderTo('linechart'); // The #id of the div where to render the chart $ob->title->text('Chart Title'); $ob->xAxis->title(array('text' => "Promedios")); $ob->yAxis->title(array('text' => "Evaluaciones")); $ob->series($series); return array('chart' => $ob, 'catedratico' => $catedratico, 'cursos' => $cursos); }
public function chartAction() { $User = $this->getUser(); $ob = new Highchart(); $ob->chart->renderTo($User->getUsername()); $ob->title->text($User->getUsername()); $ob->plotOptions->pie(array('allowPointSelect' => true, 'cursor' => 'pointer', 'dataLabels' => array('enabled' => false), 'showInLegend' => true)); $data = array(); $datag = array(); foreach ($User->getTasks() as $task) { if (array_key_exists($task->getStatus()->getName(), $data)) { $data[$task->getStatus()->getName()] = $data[$task->getStatus()->getName()] + 1; } else { $data[$task->getStatus()->getName()] = +1; } } foreach ($data as $key => $value) { $datag[] = array($key, $value); } $ob->series(array(array('type' => 'pie', 'name' => 'Estado de las tareas', 'data' => $datag))); return $this->render('TaskeetMainBundle:UserShow:chart.html.twig', array("User" => $User, 'chart' => $ob)); }
private function daychart($date) { $pgcod = $this->container->getParameter('cod.saleclose'); $repository = $this->getDoctrine()->getRepository('UerpSaleBundle:Sale'); $query = $repository->createQueryBuilder('b')->addselect('SUM(b.totalsale) as sumtotal')->where('b.date >= :datei AND b.date <= :datef AND b.status = :codpg ')->setParameters(array('datei' => $date, 'datef' => $date, 'codpg' => $pgcod))->groupBy('b.seller')->getQuery(); $ob = new Highchart(); $ob->chart->renderTo('piechart'); $ob->plotOptions->pie(array('allowPointSelect' => true, 'cursor' => 'pointer', 'dataLabels' => array('enabled' => true))); $data = array(); $em = $this->getDoctrine()->getManager(); $t = 0.0; $entities = $query->getResult(); foreach ($entities as $sale) { $entitya = $em->getRepository('UerpSellerBundle:Seller')->find($sale[0]->getseller()->getId()); $sellername = $entitya->getName(); $t += floatval($sale['sumtotal']); $data[] = array($sellername, floatval($sale['sumtotal'])); } $ob->title->text($this->get('translator')->trans('day_sales')); $ob->series(array(array('type' => 'pie', 'name' => 'Day sales', 'data' => $data))); return $ob; }
public function graphiqueNbOffre() { $query = $this->getDoctrine()->getRepository('AMiEUserBundle:User')->searchNomEntreprises(); $ent = $query->getResult(); $entreprises = array(); for ($i = 0; $i < sizeof($ent); $i++) { $entreprises[] = $ent[$i]['nom']; } $offres[0]['name'] = 'Nombre d\'offres d\'emploi postées'; $offres[0]['data'] = array(); for ($j = 0; $j < sizeof($ent); $j++) { $queryNb = $this->getDoctrine()->getRepository('AMiEOffreEmploiBundle:OffreEmploi')->searchNbOffre($ent[$j]['nom']); $nb = (int) $queryNb->getSingleScalarResult(); $offres[0]['data'][$j] = $nb; } $graph = new Highchart(); $graph->chart->renderTo('barchartNbOffre'); $graph->title->text('Nombre d\'offres d\'emploi par entreprise (inscrite)'); $graph->chart->type('column'); $graph->yAxis->title(array('text' => "Nombre d'offres")); $graph->xAxis->title(array('text' => "Entreprises")); $graph->xAxis->categories($entreprises); $graph->series($offres); return $graph; }
/** * @param $averageWeight * @param $averageBodyFat * @param $averageMuscleMass * @param $roundedCombinedRange * @param $roundedWeightRange * * @return Highchart */ private function _populateNewChart($averageWeight, $averageBodyFat, $averageMuscleMass, $roundedCombinedRange, $roundedWeightRange, $time) { $chart = new Highchart(); $series = array(array('name' => $this->_trans(StatisticEntry::WEIGHT), 'type' => 'column', 'color' => '#4572A7', 'yAxis' => 1, 'data' => array_values($averageWeight)), array('name' => $this->_trans(StatisticEntry::BODY_FAT), 'type' => 'spline', 'color' => '#AA4643', 'data' => array_values($averageBodyFat)), array('name' => $this->_trans(StatisticEntry::MUSCLE_MASS), 'type' => 'spline', 'color' => '#FAB048', 'data' => array_values($averageMuscleMass))); $yData = array(array('labels' => array('formatter' => new Expr('function () { return this.value + " ' . $this->_trans('Percent') . '" }'), 'style' => array('color' => '#AA4643')), 'title' => array('text' => $this->_trans('Body Fat') . ' / ' . $this->_trans('Muscle Mass'), 'style' => array('color' => '#AA4643')), 'opposite' => true, 'min' => $roundedCombinedRange[0], 'max' => $roundedCombinedRange[1], 'maxPadding' => 0, 'minPadding' => 0, 'tickInterval' => 5, 'tickAmount' => ($roundedCombinedRange[1] - $roundedCombinedRange[0]) / 5 + 1), array('labels' => array('formatter' => new Expr('function () { return this.value + " kg" }'), 'style' => array('color' => '#4572A7')), 'title' => array('text' => $this->_trans(StatisticEntry::WEIGHT), 'style' => array('color' => '#4572A7')), 'tickInterval' => 5, 'min' => $roundedWeightRange[0], 'tickAmount' => ($roundedWeightRange[1] - $roundedWeightRange[0]) / 5 + 1, 'endOnTick' => false, 'gridLineWidth' => 2, 'max' => $roundedWeightRange[1], 'maxPadding' => 0, 'minPadding' => 0)); $chart->yAxis($yData); $chart->chart->type('column'); $chart->chart->backgroundColor('rgba(255, 255, 255, 0.7)'); $chart->title->text($this->_trans('profile.chart.weight.headline')); $chart->xAxis->categories($time); $chart->legend->enabled(false); $formatter = new Expr('function () { var unit = { "' . $this->_trans('Weight') . '": " kg", "' . $this->_trans('Body Fat') . '": "' . $this->_trans('Body Fat') . ' %", "' . $this->_trans('Muscle Mass') . '": "' . $this->_trans('Muscle Mass') . ' %" }[this.series.name]; return this.x + ": <b>" + this.y + "</b> " + unit; }'); $chart->tooltip->formatter($formatter); $chart->series($series); return $chart; }
/** * Graph/Simulate Payment Deferrals * * @Route("/deferral/graph", name="deferral_graph", options={"expose"=true}) * @Template() */ public function graphAction(Request $request) { if ($request->getMethod() == 'POST') { $principal = (int) $request->request->get('principal'); $rate = (double) $request->request->get('rate'); $recognitionRate = (double) $request->request->get('recognitionRate'); $recognitionCap = (double) $request->request->get('recognitionCap'); $periods = (int) $request->request->get('periods'); $payments = $request->request->get('payments'); $strategy = $request->request->get('strategy'); } else { $principal = (int) $request->query->get('principal'); $rate = (double) $request->query->get('rate'); $recognitionRate = (double) $request->query->get('recognitionRate'); $recognitionCap = (double) $request->query->get('recognitionCap'); $periods = (int) $request->query->get('periods'); $payments = $request->query->get('payments'); $strategy = $request->query->get('strategy'); } if (!$principal) { $principal = 1000; } if (!$rate) { $rate = 0.75; } if (!$recognitionRate) { $recognitionRate = 1 - $rate; } if (!$recognitionCap) { $recognitionCap = $principal; } if (!$periods) { $periods = 10; } if (!$payments) { $payments = array(); } if (!$strategy) { $strategy = 'max'; } $function = $strategy == 'even' ? 'distributePaymentEvenly' : 'distributePaymentMax'; $d = new Deferral($principal, $rate, $periods); $schedule = $d->getSchedule(); $runningTotal = 0; $totals = array(); foreach ($schedule as $s) { $runningTotal += $s; $totals[] = $runningTotal; } $inits = array_fill(0, $periods, 0); $idx = 0; // Sort the $payments array by order key usort($payments, function ($a, $b) { return $a['period'] - $b['period']; }); $paymentsTotal = 0; $paymentsTotal = array_reduce($payments, function ($result, $item) { $result += $item['amount']; return $result; }); foreach ($payments as $payment) { $d = new Deferral($principal, $rate, $periods, $inits, null, $recognitionRate, $recognitionCap); $deferrals = $d->{$function}($payment['amount'], $periods - $payment['period']); $chartArrays[] = array('name' => "Payment {$idx} realized", 'type' => 'column', 'data' => $deferrals); $inits = $this->sumArraySlots($inits, $deferrals); $idx++; } // Chart $series = array(array("name" => "Monthly Payment Realized", "type" => 'column', "data" => $schedule), array("name" => "Deferral Schedule", "type" => 'spline', "data" => $totals)); $runningPaymentTotal = 0; $paymentTotals = array_fill(0, $periods, 0); if (!empty($chartArrays)) { foreach ($chartArrays as $ca) { array_push($series, $ca); $paymentTotals = $this->sumArraySlots($paymentTotals, $ca['data']); } $tally = 0; foreach ($paymentTotals as $idx => $pt) { $tally += $pt; $myTotals[] = $tally; } // Push payment totals onto series array_push($series, array('name' => 'Cumulative Payment Realized', 'type' => 'spline', 'data' => $myTotals)); } $ob = new Highchart(); $ob->chart->renderTo('linechart'); // The #id of the div where to render the chart $ob->title->text('Deferral Schedule'); $ob->xAxis->title(array('text' => "Payment Periods (months)")); $ob->yAxis->title(array('text' => "Payment Realized (dollars)")); $ob->series($series); return $this->render('TSKPaymentBundle:Deferral:graph.html.twig', array('chart' => $ob, 'principal' => $principal, 'rate' => $rate, 'recognitionRate' => $recognitionRate, 'recognitionCap' => $recognitionCap, 'periods' => $periods, 'payments' => $payments, 'paymentsTotal' => $paymentsTotal, 'strategy' => $strategy, 'evenSelected' => $strategy == 'even' ? 'selected' : '', 'maxSelected' => $strategy == 'max' ? 'selected' : '', 'admin_pool' => $this->get('sonata.admin.pool'))); }
/** * Generate aggregated reports * * @Secure(roles="ROLE_SUPER_USER,ROLE_REPORTHISTORY_GENERATE") * @Route("/", name="report_historytraining_generate") * @Method("PUT") * @Template() */ public function generateAction(Request $request) { $historytrainingForm = $this->createForm(new ReportHistoryTrainingType($this->getUser()), null, array('em' => $this->getDoctrine()->getManager())); $historytrainingForm->bind($request); if ($historytrainingForm->isValid()) { $historytrainingFormData = $historytrainingForm->getData(); $organisationUnit = $historytrainingFormData['organisationunit']; $forms = $historytrainingFormData['forms']; $reportType = $historytrainingFormData['reportType']; $withLowerLevels = $historytrainingFormData['withLowerLevels']; $fields = $historytrainingFormData['fields']; $graphType = $historytrainingFormData['graphType']; } //Create fields object is not passed from form if (is_null($fields)) { $fields = new Field(); } $results = $this->aggregationEngine($organisationUnit, $forms, $fields, $reportType, $withLowerLevels); //Get the Id for the form $formsId = $forms->getId(); //If training report generation if ($reportType == "training") { foreach ($results as $result) { $categories[] = $result['data']; $data[] = $result['total']; if ($graphType == 'pie') { $piedata[] = array('name' => $result['data'], 'y' => $result['total']); } } if ($graphType == 'pie') { $data = $piedata; } $series = array(array('name' => "Trainings", 'data' => $data)); if ($withLowerLevels) { $withLower = " with lower levels"; } $formatterLabel = 'Trainings'; $subtitle = "Trainings"; } else { if ($reportType == "history") { foreach ($results as $result) { $categories[] = $result['data']; $data[] = $result['total']; if ($graphType == 'pie') { $piedata[] = array('name' => $result['data'], 'y' => $result['total']); } } if ($graphType == 'pie') { $data = $piedata; } $series = array(array('name' => $fields->getCaption(), 'data' => $data)); if ($withLowerLevels) { $withLower = " with lower levels"; } $formatterLabel = $fields->getCaption(); $subtitle = $fields->getCaption() . " History"; } } //check which type of chart to display if ($graphType == "bar") { $graph = "column"; } elseif ($graphType == "line") { $graph = "spline"; } else { $graph = "pie"; } //set the title and sub title $title = $subtitle . " Distribution Report"; /* return array( 'organisationunit' => $organisationunit, 'forms' => $forms, 'fields' => $fields, );*/ $yData = array(array('labels' => array('formatter' => new Expr('function () { return this.value + "" }'), 'style' => array('color' => '#0D0DC1')), 'title' => array('text' => $subtitle, 'style' => array('color' => '#0D0DC1')), 'opposite' => true), array('labels' => array('formatter' => new Expr('function () { return this.value + "" }'), 'style' => array('color' => '#AA4643')), 'gridLineWidth' => 1, 'title' => array('text' => $subtitle, 'style' => array('color' => '#AA4643')))); $dashboardchart = new Highchart(); $dashboardchart->chart->renderTo('chart_placeholder_historytraining'); // The #id of the div where to render the chart $dashboardchart->chart->type($graph); $dashboardchart->title->text($title); $dashboardchart->subtitle->text($organisationUnit->getLongname() . $withLower); $dashboardchart->xAxis->categories($categories); $dashboardchart->yAxis($yData); $dashboardchart->legend->enabled(true); $formatter = new Expr('function () { var unit = { "' . $formatterLabel . '" : "' . strtolower($formatterLabel) . '", }[this.series.name]; if(this.point.name) { return ""+this.point.name+": <b>"+ this.y+"</b> "+ this.series.name; }else { return this.x + ": <b>" + this.y + "</b> " + this.series.name; } }'); $dashboardchart->tooltip->formatter($formatter); if ($graphType == 'pie') { $dashboardchart->plotOptions->pie(array('allowPointSelect' => true, 'dataLabels' => array('format' => '<b>{point.name}</b>: {point.percentage:.1f} %'))); } $dashboardchart->series($series); return array('chart' => $dashboardchart, 'data' => $data, 'categories' => $categories, 'organisationUnit' => $organisationUnit, 'formsId' => $formsId, 'reportType' => $reportType, 'withLowerLevels' => $withLowerLevels, 'fields' => $fields, 'title' => $title); }
public function hobbiesChartAction() { $id = "hobbies_chart"; $ob = new Highchart(); $ob->chart->renderTo($id); $ob->chart->type('pie'); $ob->title->text('Hobbies'); $ob->plotOptions->series(array('dataLabels' => array('enabled' => true, 'format' => '{point.name}: {point.y:.1f}%'))); $ob->tooltip->headerFormat('<span style="font-size:11px">{series.name}</span><br>'); $ob->tooltip->pointFormat('<span style="color:{point.color}">{point.name}</span>: <b>{point.y:.2f}%</b> of total<br/>'); $hobbies = $this->getDoctrine()->getManager()->getRepository('BuddySystemUserBundle:User')->getHobbies($this->container->get('section_manager')->getCurrentSection()); $total = 0; foreach ($hobbies as $hobby) { if ($hobby['name'] != null && $hobby['nb'] > 0) { $total += intval($hobby['nb']); } } $data = array(); foreach ($hobbies as $hobby) { if ($hobby['name'] != null && $hobby['nb'] > 0) { array_push($data, array($hobby['name'], round(intval($hobby['nb']) / $total * 100, 2))); } } $ob->series(array(array('name' => 'Hobbies', 'colorByPoint' => true, 'data' => $data))); return $this->render('BuddySystemMainBundle:HighCharts:chart.html.twig', array('id' => $id, 'chart' => $ob)); }
/** * Finds and displays a Portfolio entity. * * @Route("/{id}", name="portfolio_show") * @Method("GET") * @Template() */ public function showAction($id) { $em = $this->getDoctrine()->getManager(); $entity = $em->getRepository('AppBundle:Portfolio')->find($id); if (!$entity) { throw $this->createNotFoundException('Unable to find Portfolio entity.'); } $deleteForm = $this->createDeleteForm($id); //HighCharts $series = array(array("name" => "Historical Cost", "data" => ChartUtil::getChartData($entity->getHistoricalData()))); $ob = new Highchart(); $ob->chart->renderTo('linechart'); $ob->title->text('Historical Cost'); $ob->xAxis->title(array('text' => "Time")); $ob->xAxis->type('datetime'); //$ob->xAxis->format('%m/%d/%y'); $ob->yAxis->title(array('text' => "Cost")); $ob->series($series); return array('entity' => $entity, 'delete_form' => $deleteForm->createView(), 'chart' => $ob); }
public function graphiqueSalaire() { for ($an = date('Y') - 10; $an <= date('Y'); $an++) { $annees[] = $an; $querySalaire = $this->getDoctrine()->getRepository('AMiEMiagistesBundle:Formulaire')->searchSalaire($an); $moyenne[] = (int) $querySalaire->getSingleScalarResult(); // retourne un seul résultat en string qu'on caste en int } $graph = new Highchart(); $graph->chart->renderTo('splineSalaire'); $graph->title->text('Evolution du salaire brut annuel moyen prévu par années'); $graph->chart->type('spline'); $series[0]['name'] = 'Salaire moyen'; $series[0]['type'] = 'spline'; for ($i = 0; $i < sizeof($moyenne); $i++) { $series[0]['data'][] = $moyenne[$i]; } $yData = array(array('title' => array('text' => "Salaire moyen (brut)"))); $graph->yAxis($yData); $graph->xAxis->title(array('text' => "Années")); $graph->xAxis->categories($annees); $graph->series($series); return $graph; }
/** * Generate aggregated reports * * @Secure(roles="ROLE_SUPER_USER,ROLE_REPORTAGGREGATION_GENERATE") * @Route("/", name="report_aggregation_generate") * @Method("PUT") * @Template() */ public function generateAction(Request $request) { $aggregationForm = $this->createForm(new ReportAggregationType($this->getUser()), null, array('em' => $this->getDoctrine()->getManager())); $aggregationForm->bind($request); if ($aggregationForm->isValid()) { $aggregationFormData = $aggregationForm->getData(); $organisationUnit = $aggregationFormData['organisationunit']; $forms = $aggregationFormData['forms']; $organisationunitGroup = $aggregationFormData['organisationunitGroup']; $withLowerLevels = $aggregationFormData['withLowerLevels']; $fields = $aggregationFormData['fields']; $fieldsTwo = $aggregationFormData['fieldsTwo']; $graphType = $aggregationFormData['graphType']; } if (empty($organisationUnit)) { $organisationUnit = $this->getDoctrine()->getManager()->createQuery('SELECT organisationunit FROM HrisOrganisationunitBundle:Organisationunit organisationunit WHERE organisationunit.parent IS NULL')->getSingleResult(); } $results = $this->aggregationEngine($organisationUnit, $forms, $fields, $organisationunitGroup, $withLowerLevels, $fieldsTwo); //handle the exception when there is no data $data = NULL; $categories = NULL; //Get the Id for the forms $formsId = ''; foreach ($forms as $form) { $formsId .= $form->getId() . ","; } $formsId = rtrim($formsId, ","); //Get the Id for the OrgansiationunitGoup $organisationunitGroupId = ''; foreach ($organisationunitGroup as $organisationunitGroups) { $organisationunitGroupId .= $organisationunitGroups->getId() . ","; } $organisationunitGroupId = rtrim($organisationunitGroupId, ","); //if only one field selected if ($fieldsTwo->getId() == $fields->getId()) { foreach ($results as $result) { $categories[] = $result[strtolower($fields->getName())]; $data[] = $result['total']; if ($graphType == 'pie') { $piedata[] = array('name' => $result[strtolower($fields->getName())], 'y' => $result['total']); } } if ($graphType == 'pie') { $data = $piedata; } $series = array(array('name' => $fields->getName(), 'data' => $data)); $formatterLabel = $fields->getCaption(); } else { //Two fields selected $tempCategory = NULL; $tempFieldOption = NULL; $i = 0; foreach ($results as $result) { if ($result[strtolower($fields->getName())] != $tempCategory && $i != 0) { foreach ($fieldsTwo->getFieldOption() as $fieldOption) { if (!in_array($fieldOption->getValue(), $tempFieldOption)) { $keys[$fieldOption->getValue()][] = 0; } } $tempFieldOption = NULL; } $keys[$result[strtolower($fieldsTwo->getName())]][] = $result['total']; $categoryKeys[$result[strtolower($fields->getName())]] = $result['total']; $tempCategory = $result[strtolower($fields->getName())]; $tempFieldOption[] = $result[strtolower($fieldsTwo->getName())]; $i++; //if($i==4) {print_r($keys);die();} } $series = array(); foreach ($keys as $key => $values) { $series[] = array('name' => $key, 'yAxis' => 1, 'data' => $values); } $formatterLabel = $fieldsTwo->getCaption(); $categories = array_keys($categoryKeys); } //check which type of chart to display if ($graphType == "bar") { $graph = "column"; } elseif ($graphType == "line") { $graph = "spline"; } else { $graph = "pie"; } //set the title and sub title $title = $fields->getCaption() . " Distribution"; if ($fieldsTwo->getId() != $fields->getId()) { $title .= " with " . $fieldsTwo->getCaption() . " cross Tabulation "; } /* return array( 'organisationunit' => $organisationunit, 'forms' => $forms, 'fields' => $fields, );*/ $yData = array(array('labels' => array('formatter' => new Expr('function () { return this.value + "" }'), 'style' => array('color' => '#0D0DC1')), 'title' => array('text' => $fields->getCaption(), 'style' => array('color' => '#0D0DC1')), 'opposite' => true), array('labels' => array('formatter' => new Expr('function () { return this.value + "" }'), 'style' => array('color' => '#AA4643')), 'gridLineWidth' => 1, 'title' => array('text' => $fields->getCaption(), 'style' => array('color' => '#AA4643')))); $dashboardchart = new Highchart(); $dashboardchart->chart->renderTo('chart_placeholder'); // The #id of the div where to render the chart $dashboardchart->chart->type($graph); $dashboardchart->title->text($title); $dashboardchart->subtitle->text($organisationUnit->getLongname() . ' with lower levels'); $dashboardchart->xAxis->categories($categories); $dashboardchart->xAxis->labels(array('rotation' => 45)); $dashboardchart->yAxis($yData); if ($fieldsTwo->getId() == $fields->getId()) { $dashboardchart->legend->enabled(true); } else { $dashboardchart->legend->enabled(true); } $formatter = new Expr('function () { var unit = { "' . $formatterLabel . '" : "' . strtolower($formatterLabel) . '", }[this.series.name]; if(this.point.name) { return ""+this.point.name+": <b>"+ this.y+"</b> "+ this.series.name; }else { return this.x + ": <b>" + this.y + "</b> " + this.series.name; } }'); $dashboardchart->tooltip->formatter($formatter); if ($graphType == 'pie') { $dashboardchart->plotOptions->pie(array('allowPointSelect' => true, 'dataLabels' => array('format' => '<b>{point.name}</b>: {point.percentage:.1f} %'))); } $dashboardchart->series($series); return array('chart' => $dashboardchart, 'organisationUnit' => $organisationUnit, 'formsId' => $formsId, 'organisationunitGroupId' => $organisationunitGroupId, 'withLowerLevels' => $withLowerLevels, 'fields' => $fields, 'fieldsTwo' => $fieldsTwo); }
/** * Sales per month overview * * @Route("/tags", name="chart_tags") * @Method("GET") */ public function tagsAction() { $em = $this->getDoctrine()->getManager(); $translator = $this->get('translator'); $tags = $em->getRepository('AffiliateDashboardBundle:Tag')->findAll(); // Chart $series = array(); $keys = array(); /** @var $tag Tag */ foreach ($tags as $tag) { $sales = $em->getRepository('AffiliateDashboardBundle:Sale')->getSalesPerDay($tag); $series[] = array('name' => $tag->getName(), 'data' => $sales); $keys = array_unique(array_merge($keys, array_keys($sales))); } sort($keys); // Fill missing values with 0 foreach ($series as $key => $serie) { $series[$key]['data'] = array_values(array_replace(array_fill_keys($keys, array(0)), $serie['data'])); } $ob = new Highchart(); $ob->chart->type('line'); $ob->chart->renderTo('chart'); $ob->title->text($translator->trans('Sales per day')); $ob->xAxis->categories($keys); $ob->xAxis->title(array('text' => $translator->trans('Day'))); $ob->xAxis->type('date'); $ob->yAxis->title(array('text' => $translator->trans('Euro'))); $ob->series($series); return $this->render('AffiliateDashboardBundle:Chart:chart.html.twig', array('chart' => $ob)); }
public function chartAction() { $ob = new Highchart(); $ob->chart->renderTo('piechart'); $ob->title->text('Browser market shares at a specific website in 2010'); $ob->plotOptions->pie(array('allowPointSelect' => true, 'cursor' => 'pointer', 'dataLabels' => array('enabled' => false), 'showInLegend' => true)); $data = array(array('Firefox', 45.0), array('IE', 26.8), array('Chrome', 12.8), array('Safari', 8.5), array('Opera', 6.2), array('Others', 0.7)); $ob->series(array(array('type' => 'pie', 'name' => 'Browser share', 'data' => $data))); return $this->render('UmgVotacionBundle:Default:chart.html.twig', array('chart' => $ob)); }
/** * @Security("has_role('ROLE_CA')") * A chart displaying how much a skill has brought in turnover */ private function getCACompetences() { $etude_manager = $this->get('Mgate.etude_manager'); $MANDAT_MAX = $etude_manager->getMaxMandat(); $MANDAT_MIN = $etude_manager->getMinMandat(); $em = $this->getDoctrine()->getManager(); $res = $em->getRepository('N7consultingRhBundle:Competence')->getAllEtudesByCompetences(); //how much each skill has make us earn. $series = array(); $categories = array(); $used_mandats = array_fill(0, $MANDAT_MAX - $MANDAT_MIN + 1, 0); // an array to post-process results and remove mandats without data. //create array structure foreach ($res as $c) { $temp = array('name' => $c->getNom(), 'data' => array_fill(0, $MANDAT_MAX - $MANDAT_MIN + 1, 0)); $sumSkill = 0; foreach ($c->getEtudes() as $e) { $temp['data'][$e->getMandat() - $MANDAT_MIN] += $e->getMontantHT(); $used_mandats[$e->getMandat() - $MANDAT_MIN] += 1; $sumSkill += $e->getMontantHT(); } if ($sumSkill > 0) { $series[] = $temp; } } for ($i = $MANDAT_MIN; $i <= $MANDAT_MAX; $i++) { $categories[] = 'Mandat ' . $i; } //remove mandats with no skills used //once array has been spliced, index will be changed. Therefore, we uses $k has read index $k = 0; for ($i = 0; $i <= $MANDAT_MAX - $MANDAT_MIN; $i++) { if ($used_mandats[$i] == 0 && isset($categories[$k])) { array_splice($categories, $k, 1); $count_series = count($series); for ($j = 0; $j < $count_series; $j++) { array_splice($series[$j]['data'], $k, 1); } } else { $k++; } } $ob = new Highchart(); // ID de l'élement de DOM que vous utilisez comme conteneur $ob->chart->renderTo(__FUNCTION__); $ob->title->text('Revenus par compétences'); $ob->chart->type('column'); $ob->plotOptions->pie(array('allowPointSelect' => true, 'cursor' => 'pointer', 'showInLegend' => true, 'dataLabels' => array('enabled' => false))); $ob->title->style(array('fontWeight' => 'bold', 'fontSize' => '20px')); $ob->credits->enabled(false); $ob->yAxis->title(array('text' => 'Revenus par compétences')); $ob->xAxis->title(array('text' => 'Mandats')); $ob->xAxis->categories($categories); $ob->series($series); return $this->render('MgateStatBundle:Indicateurs:Indicateur.html.twig', array('chart' => $ob)); }