Exemple #1
0
 public function chartHistogrammeAction()
 {
     $series = array(array('name' => 'Rainfall', 'type' => 'column', 'color' => '#4572A7', 'yAxis' => 1, 'data' => array(49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.59999999999999, 54.4)), array('name' => 'Temperature', 'type' => 'spline', 'color' => '#AA4643', 'data' => array(7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6)));
     $yData = array(array('labels' => array('formatter' => new Expr('function () { return this.value + " degrees C" }'), 'style' => array('color' => '#AA4643')), 'title' => array('text' => 'Temperature', 'style' => array('color' => '#AA4643')), 'opposite' => true), array('labels' => array('formatter' => new Expr('function () { return this.value + " mm" }'), 'style' => array('color' => '#4572A7')), 'gridLineWidth' => 0, 'title' => array('text' => 'Rainfall', 'style' => array('color' => '#4572A7'))));
     $categories = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
     $ob = new Highchart();
     $ob->chart->renderTo('container');
     $ob->chart->type('column');
     $ob->title->text('Average Monthly Weather Data for Tokyo');
     $ob->xAxis->categories($categories);
     $ob->yAxis($yData);
     $ob->legend->enabled(false);
     $formatter = new Expr('function () {                  var unit = {                      "Rainfall": "mm",                      "Temperature": "degrees C"                  }[this.series.name];                  return this.x + ": <b>" + this.y + "</b> " + unit;              }');
     $ob->tooltip->formatter($formatter);
     $ob->series($series);
     return $this->render('MyAppGrapheBundle:Graphe:histogramme.html.twig', array('chart' => $ob));
 }
 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);
 }
 /**
  * @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;
 }
    /**
     * 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);
    }
Exemple #5
0
 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);
    }
    /**
     * Generate aggregated reports
     *
     * @Secure(roles="ROLE_SUPER_USER,ROLE_REPORTHISTORY_GENERATE")
     * @Route("/", name="report_trainingreports_generate")
     * @Method("PUT")
     * @Template()
     */
    public function generateAction(Request $request)
    {
        $historytrainingForm = $this->createForm(new ReportTrainingType($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'];
            $graphType = $historytrainingFormData['graphType'];
            $startdate = $historytrainingFormData['from'];
            $enddate = $historytrainingFormData['to'];
            $trainings = $historytrainingFormData['Trainings'];
            $groups = array('0' => 00);
            foreach ($trainings as $group) {
                $groups_ids[] = $group->getId();
                $group_names[] = $group->getCoursename();
            }
            $groups[0] = $groups_ids;
            $groups[1] = $group_names;
            $formIds = array('0' => 00);
            foreach ($forms as $form) {
                $formIds[] = $form->getId();
            }
        }
        if ($reportType == "facilitators" || $reportType == "participants" || $reportType == "trainings") {
            $groups_results = $this->aggregationEngine($organisationUnit, $groups, $formIds, $reportType, $withLowerLevels, $startdate, $enddate);
            $perfectArray = $this->reportGroupArray($groups, $startdate, $enddate);
            $groups_series = array();
            $categories = array();
            foreach ($perfectArray as $results) {
                $data = array();
                foreach ($groups_results as $resforgroups) {
                    if ($resforgroups[0] == $results[0]) {
                        $containedDataArray = array();
                        foreach ($resforgroups[1] as $resforgroup) {
                            $containedDataArray[$resforgroup['data']] = $resforgroup['total'];
                        }
                        foreach ($results[1] as $result) {
                            $categories[] = json_decode('[' . $result['data'] . ']', true);
                            //$result['data'];
                            if (array_key_exists($result['data'], $containedDataArray)) {
                                $data[] = json_decode('[' . $containedDataArray[$result['data']] . ']', true);
                            } else {
                                $data[] = $result['total'];
                            }
                            if ($graphType == 'pie') {
                                $piedata[] = array('name' => $result['data'], 'y' => $result['total']);
                            }
                        }
                    }
                }
                $groups_series[] = array('name' => $results[0], 'data' => $data);
            }
            $cats = array_map("unserialize", array_unique(array_map("serialize", $categories)));
            $categories = array();
            foreach ($cats as $cat) {
                $categories[] = $cat;
            }
            $series = $groups_series;
            if ($withLowerLevels) {
                $withLower = " with lower levels";
            }
            if ($reportType == "facilitators") {
                $formatterLabel = 'Facilitators';
                $subtitle = "Facilitators";
            } elseif ($reportType == "participants") {
                $formatterLabel = 'Participants';
                $subtitle = "Participants";
            } elseif ($reportType == "trainings") {
                $formatterLabel = 'Trainings';
                $subtitle = "Trainings";
            }
        }
        //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";
        $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);
        $forms_id = "";
        foreach ($formIds as $ids) {
            $forms_id .= "_" . $ids;
        }
        return array('chart' => $dashboardchart, 'data' => $data, 'categories' => $categories, 'organisationUnit' => $organisationUnit, 'forms' => $forms, 'formIds' => $forms_id, 'groups' => $groups, 'reportType' => $reportType, 'withLowerLevels' => $withLowerLevels, 'title' => $title, 'result2' => $result, 'startdate' => $startdate, 'enddate' => $enddate);
    }
    private function constructChartAction($fieldOne, $fieldTwo, $data, $organisationUnit, $categories, $graph, $title, $placeholder)
    {
        if ($fieldOne->getId() == $fieldTwo->getId()) {
            $series = array(array('name' => $fieldOne->getName(), 'data' => $data));
            $formatterLabel = $fieldOne->getCaption();
        } else {
            $series = $data;
            $formatterLabel = $fieldTwo->getCaption();
        }
        $yData = array(array('labels' => array('formatter' => new Expr('function () { return this.value + "" }'), 'style' => array('color' => '#0D0DC1')), 'title' => array('text' => $fieldOne->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' => $fieldOne->getCaption(), 'style' => array('color' => '#AA4643'))), 'min' => 0, 'startOnTick' => false);
        if (!isset($data)) {
            $data = array();
        }
        if (!isset($data)) {
            $data = array();
        }
        $arrayResult = array_filter($data, function ($value) {
            return $value > 0;
        });
        if (empty($arrayResult)) {
            $yData['max'] = 5;
        }
        $dashboardchart = new Highchart();
        $dashboardchart->chart->renderTo($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->yAxis($yData);
        if ($fieldOne->getId() == $fieldTwo->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 ($graph == 'pie') {
            $dashboardchart->plotOptions->pie(array('allowPointSelect' => true, 'dataLabels' => array('format' => '<b>{point.name}</b>: {point.percentage:.1f} %')));
        }
        $dashboardchart->series($series);
        return $dashboardchart;
    }