public function chartDataAction() { // Disable layout and viewrenderer $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(true); // Get params $type = $this->_getParam('type'); $start = $this->_getParam('start'); $offset = $this->_getParam('offset', 0); $mode = $this->_getParam('mode'); $chunk = $this->_getParam('chunk'); $period = $this->_getParam('period'); $periodCount = $this->_getParam('periodCount', 1); //$end = $this->_getParam('end'); // Validate chunk/period if (!$chunk || !in_array($chunk, $this->_periods)) { $chunk = Zend_Date::DAY; } if (!$period || !in_array($period, $this->_periods)) { $period = Zend_Date::MONTH; } if (array_search($chunk, $this->_periods) >= array_search($period, $this->_periods)) { die('whoops'); return; } // Validate start if ($start && !is_numeric($start)) { $start = strtotime($start); } if (!$start) { $start = time(); } // Fixes issues with month view Zend_Date::setOptions(array('extend_month' => true)); // Get timezone $timezone = Engine_Api::_()->getApi('settings', 'core')->getSetting('core_locale_timezone', 'GMT'); $viewer = Engine_Api::_()->user()->getViewer(); if ($viewer && $viewer->getIdentity() && !empty($viewer->timezone)) { $timezone = $viewer->timezone; } // Make start fit to period? $startObject = new Zend_Date($start); $startObject->setTimezone($timezone); $partMaps = $this->_periodMap[$period]; foreach ($partMaps as $partType => $partValue) { $startObject->set($partValue, $partType); } // Do offset if ($offset != 0) { $startObject->add($offset, $period); } // Get end time $endObject = new Zend_Date($startObject->getTimestamp()); $endObject->setTimezone($timezone); $endObject->add($periodCount, $period); $endObject->sub(1, Zend_Date::SECOND); // Subtract one second // Get data $statsTable = Engine_Api::_()->getDbtable('statistics', 'core'); $statsSelect = $statsTable->select()->where('type = ?', $type)->where('date >= ?', gmdate('Y-m-d H:i:s', $startObject->getTimestamp()))->where('date < ?', gmdate('Y-m-d H:i:s', $endObject->getTimestamp()))->order('date ASC'); $rawData = $statsTable->fetchAll($statsSelect); // Now create data structure $currentObject = clone $startObject; $nextObject = clone $startObject; $data = array(); $dataLabels = array(); $cumulative = 0; $previous = 0; do { $nextObject->add(1, $chunk); $currentObjectTimestamp = $currentObject->getTimestamp(); $nextObjectTimestamp = $nextObject->getTimestamp(); $data[$currentObjectTimestamp] = $cumulative; // Get everything that matches $currentPeriodCount = 0; foreach ($rawData as $rawDatum) { $rawDatumDate = strtotime($rawDatum->date); if ($rawDatumDate >= $currentObjectTimestamp && $rawDatumDate < $nextObjectTimestamp) { $currentPeriodCount += $rawDatum->value; } } // Now do stuff with it switch ($mode) { default: case 'normal': $data[$currentObjectTimestamp] = $currentPeriodCount; break; case 'cumulative': $cumulative += $currentPeriodCount; $data[$currentObjectTimestamp] = $cumulative; break; case 'delta': $data[$currentObjectTimestamp] = $currentPeriodCount - $previous; $previous = $currentPeriodCount; break; } $currentObject->add(1, $chunk); } while ($currentObject->getTimestamp() < $endObject->getTimestamp()); // Reprocess label $labelStrings = array(); $labelDate = new Zend_Date(); foreach ($data as $key => $value) { $labelDate->set($key); $labelStrings[] = $this->view->locale()->toDate($labelDate, array('size' => 'short')); //date('D M d Y', $key); } // Let's expand them by 1.1 just for some nice spacing $minVal = min($data); $maxVal = max($data); $minVal = floor($minVal * ($minVal < 0 ? 1.1 : 1 / 1.1) / 10) * 10; $maxVal = ceil($maxVal * ($maxVal > 0 ? 1.1 : 1 / 1.1) / 10) * 10; // Remove some labels if there are too many $xlabelsteps = 1; if (count($data) > 10) { $xlabelsteps = ceil(count($data) / 10); } // Remove some grid lines if there are too many $xsteps = 1; if (count($data) > 100) { $xsteps = ceil(count($data) / 100); } // Create base chart require_once 'OFC/OFC_Chart.php'; // Make x axis labels $x_axis_labels = new OFC_Elements_Axis_X_Label_Set(); $x_axis_labels->set_steps($xlabelsteps); $x_axis_labels->set_labels($labelStrings); // Make x axis $labels = new OFC_Elements_Axis_X(); $labels->set_labels($x_axis_labels); $labels->set_colour("#416b86"); $labels->set_grid_colour("#dddddd"); $labels->set_steps($xsteps); // Make y axis $yaxis = new OFC_Elements_Axis_Y(); $yaxis->set_range($minVal, $maxVal); $yaxis->set_colour("#416b86"); $yaxis->set_grid_colour("#dddddd"); // Make data $graph = new OFC_Charts_Line(); $graph->set_values(array_values($data)); $graph->set_colour("#5ba1cd"); // Make title $locale = Zend_Registry::get('Locale'); $translate = Zend_Registry::get('Zend_Translate'); $titleStr = $translate->_('_CORE_ADMIN_STATS_' . strtoupper(trim(preg_replace('/[^a-zA-Z0-9]+/', '_', $type), '_'))); $title = new OFC_Elements_Title($titleStr . ': ' . $this->view->locale()->toDateTime($startObject) . ' to ' . $this->view->locale()->toDateTime($endObject)); $title->set_style("{font-size: 14px;font-weight: bold;margin-bottom: 10px; color: #777777;}"); // Make full chart $chart = new OFC_Chart(); $chart->set_bg_colour('#ffffff'); $chart->set_x_axis($labels); $chart->add_y_axis($yaxis); $chart->add_element($graph); $chart->set_title($title); // Send $this->getResponse()->setBody($chart->toPrettyString()); }
for ($i = 0; $i < 6.2; $i += 0.2) { $tmp = sin($i) * 1.9; $data[] = $tmp; } require_once 'OFC/OFC_Chart.php'; $chart = new OFC_Chart(); $chart->set_title(new OFC_Elements_Title('Area Chart')); // // Make our area chart: // $area = new OFC_Charts_Area_Hollow(); // set the circle line width: $area->set_width(1); $area->set_values($data); // add the area object to the chart: $chart->add_element($area); $y_axis = new OFC_Elements_Axis_Y(); $y_axis->set_range(-2, 2, 2); $y_axis->labels = null; $y_axis->set_offset(false); $x_axis = new OFC_Elements_Axis_X(); $x_axis->labels = $data; $x_axis->set_steps(2); $x_labels = new OFC_Elements_Axis_X_Label_Set(); $x_labels->set_steps(4); $x_labels->set_vertical(); // Add the X Axis Labels to the X Axis $x_axis->set_labels($x_labels); $chart->add_y_axis($y_axis); $chart->x_axis = $x_axis; echo $chart->toPrettyString();
* License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ require_once 'OFC/OFC_Chart.php'; $title = new OFC_Elements_Title("Our New House Schedule"); $hbar = new OFC_Charts_Bar_Horizontal(); $hbar->append_value(new OFC_Charts_Bar_Horizontal_Value(0, 4)); $hbar->append_value(new OFC_Charts_Bar_Horizontal_Value(4, 8)); $hbar->append_value(new OFC_Charts_Bar_Horizontal_Value(8, 11)); $chart = new OFC_Chart(); $chart->set_title($title); $chart->add_element($hbar); $chart->add_y_axis(new OFC_Elements_Axis_Y()); $x = new OFC_Elements_Axis_X(); $x->set_offset(false); $x->set_labels_from_array(array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec')); $chart->set_x_axis($x); $y = new OFC_Elements_Axis_Y(); $y->set_offset(true); $y->set_labels(array("Make garden look sexy", "Paint house", "Move into house")); $chart->add_y_axis($y); echo $chart->toPrettyString();
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ require_once 'OFC/OFC_Chart.php'; $chart = new OFC_Chart(); $title = new OFC_Elements_Title(date("D M d Y")); $chart->set_title($title); $scatter = new OFC_Charts_Scatter('#FFD600', 10); $scatter->set_values(array(new OFC_Charts_Scatter_Value(0, 0))); $chart->add_element($scatter); // // plot a circle // $s2 = new OFC_Charts_Scatter('#D600FF', 3); $v = array(); for ($i = 0; $i < 360; $i += 5) { $v[] = new OFC_Charts_Scatter_Value(number_format(sin(deg2rad($i)), 2, '.', ''), number_format(cos(deg2rad($i)), 2, '.', '')); } $s2->set_values($v); $chart->add_element($s2); $x = new OFC_Elements_Axis_X(); $x->set_range(-2, 2); $chart->set_x_axis($x); $y = new OFC_Elements_Axis_Y(); $y->set_range(-2, 2); $chart->add_y_axis($y); echo $chart->toPrettyString();
public function deploy() { $this->checkExportRights(); if ($this->_filesLocation === null) { throw new Bvb_Grid_Exception($this->__("Please set Javascript and Flash file locations using SetFilesLocation()")); } $grid = array(); $newData = array(); $label = array(); $result = array(); parent::deploy(); $data = parent::_buildGrid(); if (count($data) == 0) { $this->_deploymentContent = ''; return; } foreach ($data as $value) { foreach ($value as $final) { $result[$final['field']][] = is_numeric($final['value']) ? $final['value'] : strip_tags($final['value']); } } if (is_string($this->_xLabels) && isset($result[$this->_xLabels])) { $this->_xLabels = $result[$this->_xLabels]; } $graph = new OFC_Chart(); $title = new OFC_Elements_Title($this->_title); $title->set_style($this->_style); $graph->set_title($title); foreach ($this->_chartOptions as $key => $value) { $graph->{$key}($value); } if (count($this->_xLabels) > 0) { $x = new OFC_Elements_Axis_X(); $x_axis_labels = new OFC_Elements_Axis_X_Label_Set(); foreach ($this->_xAxisOptions as $key => $value) { $x_axis_labels->{$key}($value); } $x_axis_labels->set_labels($this->_xLabels); $x->set_labels($x_axis_labels); foreach ($this->_xLabelsOptions as $key => $value) { $x->{$key}($value); } $graph->set_x_axis($x); } if (!empty($this->_xLegendText) && !empty($this->_xLegendStyle)) { $x_legend = new OFC_Elements_Legend_X($this->_xLegendText); $x_legend->set_style($this->_xLegendStyle); $graph->set_x_legend($x_legend); } $min = 0; $max = 0; if (count($this->_values) == 0) { $this->setValues(key($result)); } foreach ($this->_values as $key => $value) { if (is_array($value)) { $support = $value; sort($support); if (reset($support) < $min) { $min = reset($support); } if (end($support) > $max) { $max = end($support); } unset($support); $options = $this->_chartOptionsValues[$value]; if (isset($options['chartType'])) { $this->setChartType($options['chartType']); } $bar = new $this->_type(); foreach ($options as $key => $prop) { $bar->{$key}($prop); } $this->_type(); $pie = array(); if ($this->_type == 'Pie') { foreach ($value as $key => $title) { $pie[] = array('value' => $title, 'label' => $this->_xLabels[$key]); } $bar->set_values($pie); } else { $bar->set_values($value); } $graph->add_element($bar); } elseif (is_string($value) && isset($result[$value])) { $options = $this->_chartOptionsValues[$value]; if (isset($options['chartType'])) { $this->setChartType($options['chartType']); } $bar = new $this->_type(); foreach ($options as $key => $prop) { $bar->{$key}($prop); } $value = array_map(create_function('$item', ' return (float)$item; '), $result[$value]); $support = $value; sort($support); if (reset($support) < $min) { $min = reset($support); } if (end($support) > $max) { $max = end($support); } unset($support); $pie = array(); if ($this->_type == 'OFC_Charts_Pie') { foreach ($value as $key => $title) { $pie[] = array('value' => $title, 'label' => $this->_xLabels[$key]); } $bar->set_values($pie); } else { $bar->set_values($value); } $graph->add_element($bar); } } $max = $max * 1.05; $y = new OFC_Elements_Axis_Y(); $y->set_range($min, $max, ceil($max / 4)); $graph->add_y_axis($y); $final = $graph->toPrettyString(); if (!is_string($this->_chartId)) { $this->_chartId = 'chart_' . rand(1, 10000); } $script = ' swfobject.embedSWF( "' . $this->_filesLocation['flash'] . '", "' . $this->_chartId . '", "' . $this->_chartDimensions['x'] . '", "' . $this->_chartDimensions['y'] . '", "9.0.0", "expressInstall.swf",{"id":"' . $this->_chartId . '"},{"z-index":"1","wmode":"transparent"} ); function open_flash_chart_data(id) { return JSON.stringify(window[id]); } function findSWF(movieName) { if (navigator.appName.indexOf("Microsoft")!= -1) { return window[movieName]; } else { return document[movieName]; } } var ' . $this->_chartId . ' = ' . $final . ';'; $final = '<div id="' . $this->_chartId . '" > loading... <br/> <p> Please note that this content requires flash player 9.0.0</br> To test for your version of flash, <a href="http://www.bobbyvandersluis.com/swfobject/testsuite_2_1/test_api_getflashplayerversion.html" target="_blank">click here</a> </p> </div>'; if (!$this->_multiple) { $final = '<div style="width: 100%;text-align: center">' . $final . '</div>'; } $this->getView()->headScript()->appendFile($this->_filesLocation['js']); $this->getView()->headScript()->appendFile($this->_filesLocation['json']); $this->getView()->headScript()->appendScript($script); $this->_deploymentContent = $final; return $this; }
/** * @Route("/{anno}/{mes}/{assigned_user_id}/{width}/panel_detalle_discovery_metas_in_progress_data.json", name="panel_detalle_discovery_metas_in_progress_data", defaults={"anno"="2013","mes"="01"}, options={"expose"=true}) */ public function panelDetalleDiscoveryMetasPorAgenteDataAction($anno, $mes, $assigned_user_id, $width) { include_once __DIR__ . "/../Util/OFC/OFC_Chart.php"; $title = new \OFC_Elements_Title('STATUS DE LAS REUNIONES V/S METAS DEL AGENTE '); $bar = new \OFC_Charts_Bar_Stack(); $sql = "SELECT CONCAT(users.user_name,' ',users.first_name,' ', users.last_name) as owner, meetings.assigned_user_id, (SELECT count(*) FROM meetings m WHERE parent_type = 'Accounts' AND m.deleted = 0 AND YEAR(m.date_start) = 2015 AND m.assigned_user_id = meetings.assigned_user_id ) as meetings,(SELECT count(*) FROM meetings m2 INNER JOIN accounts_opportunities ON m2.parent_id = accounts_opportunities.opportunity_id WHERE parent_type = 'Opportunities' AND 1 AND m2.deleted = 0 AND YEAR(m2.date_start) = " . $anno . " ) as meetings_opportunities FROM meetings INNER JOIN users ON users.id = meetings.assigned_user_id AND meetings.deleted = 0 AND meetings.assigned_user_id = '" . $assigned_user_id . "' GROUP BY assigned_user_id HAVING (meetings + meetings_opportunities) > 0;"; $stmt = $this->container->get('doctrine')->getManager()->getConnection()->prepare($sql); $stmt->execute(); //Valores $valor = 0; foreach ($stmt->fetchAll() as $data) { $valor = (int) $data['meetings'] + (int) $data['meetings_opportunities']; $bar->append_stack(array(new \OFC_Charts_Bar_Stack_Value((int) $data['meetings'], '#ff0000'), new \OFC_Charts_Bar_Stack_Value((int) $data['meetings_opportunities'], '#1240AB'))); } //Metas $sql = "SELECT sem_1_c, sem_2_c FROM cammr_metasreuniones INNER JOIN cammr_metasreuniones_cstm ON cammr_metasreuniones_cstm.id_c = cammr_metasreuniones.id WHERE deleted = 0 AND anno_c = '" . $anno . "' AND user_id_c = '" . $assigned_user_id . "';"; $stmt = $this->container->get('doctrine')->getManager()->getConnection()->prepare($sql); $stmt->execute(); $meta = 0; foreach ($stmt->fetchAll() as $data) { $meta = $data['sem_1_c'] + $data['sem_2_c']; $bar->append_stack(array(new \OFC_Charts_Bar_Stack_Value((int) $data['sem_1_c'], '#ff0000'), new \OFC_Charts_Bar_Stack_Value((int) $data['sem_2_c'], '#1240AB'))); } $y = new \OFC_Elements_Axis_Y(); $max = round(max($valor, $meta) * 1.15, 0); $y->set_range(0, $max, round($max, -3)); $x = new \OFC_Elements_Axis_X(); $x->set_labels_from_array(array('Reuniones', 'Metas')); $chart = new \OFC_Chart(); $chart->set_bg_colour('#FFFFFF'); $chart->set_title($title); $chart->add_element($bar); $chart->set_x_axis($x); $chart->add_y_axis($y); $response = new Response($chart->toPrettyString()); $response->headers->set('Content-Type', 'application/json'); return $response; }