예제 #1
0
	public function body() {
		$f = $this->init_module('Libs/OpenFlashChart');

		$title = new OFC_Elements_Title( date("D M d Y") );
		$f->set_title( $title );

		$bar = new OFC_Charts_Bar();
		$bar->set_values( array(9,8,7,6,5,4,3,2,1) );
		$f->add_element( $bar );

		$this->display_module($f);

		$f2 = $this->init_module('Libs/OpenFlashChart');

		$title = new OFC_Elements_Title( date("D M d Y") );
		$f2->set_title( $title );

		$bar = new OFC_Charts_Bar_Glass();
		$data = array();
		for($i=1; $i<10; $i++)
			$data[] = rand()%10;
		$bar->set_values( $data );
		$f2->add_element( $bar );

		$bar = new OFC_Charts_Line();
		$data = array();
		for($i=1; $i<10; $i++)
			$data[] = rand()%10;
		$bar->set_values( $data );
		$bar->set_colour('#FF0000');
		$f2->add_element( $bar );

		$this->display_module($f2);

		//------------------------------ print out src
		print('<hr><b>Install</b><br>');
		$this->pack_module('Utils/CatFile','modules/Tests/OpenFlashChart/OpenFlashChartInstall.php');
		print('<hr><b>Main</b><br>');
		$this->pack_module('Utils/CatFile','modules/Tests/OpenFlashChart/OpenFlashChart_0.php');
		print('<hr><b>Common</b><br>');
		$this->pack_module('Utils/CatFile','modules/Tests/OpenFlashChart/OpenFlashChartCommon_0.php');
	
	}
예제 #2
0
 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());
 }
예제 #3
0
 public function draw_category_chart($ref_rec, $gb_captions)
 {
     $f = $this->init_module(Libs_OpenFlashChart::module_name());
     $title = new OFC_Elements_Title($ref_rec);
     $f->set_title($title);
     $labels = array();
     foreach ($gb_captions as $cap) {
         $labels[] = $cap['name'];
     }
     $x_ax = new OFC_Elements_Axis_X();
     $x_ax->set_labels_from_array($labels);
     $f->set_x_axis($x_ax);
     $max = 5;
     $color = 0;
     foreach ($this->ref_records as $q => $r) {
         $results = call_user_func($this->display_cell_callback, $r);
         $title2 = strip_tags(call_user_func($this->ref_record_display_callback, $r, true));
         $bar = new OFC_Charts_Line();
         $bar->set_colour(self::$colours[$color % count(self::$colours)]);
         $color++;
         $bar->set_key($title2, 10);
         $arr = array();
         foreach ($results as $v) {
             if ($ref_rec) {
                 if (is_array($v[$ref_rec])) {
                     $v[$ref_rec] = array_pop($v[$ref_rec]);
                 }
                 $val = (double) strip_tags($v[$ref_rec]);
             } else {
                 if (is_array($v)) {
                     $v = array_pop($v);
                 }
                 $val = (double) strip_tags($v);
             }
             $arr[] = $val;
             if ($max < $val) {
                 $max = $val;
             }
         }
         $bar->set_values($arr);
         $f->add_element($bar);
     }
     $y_ax = new OFC_Elements_Axis_Y();
     $y_ax->set_range(0, $max);
     $y_ax->set_steps($max / 10);
     $f->set_y_axis($y_ax);
     $f->set_width(950);
     $f->set_height(400);
     $this->display_module($f);
 }
예제 #4
0
    $data_1[] = rand(1, 6);
    $data_2[] = rand(7, 13);
    $data_3[] = rand(14, 19);
}
$line_dot = new OFC_Charts_Line_Dot();
$line_dot->set_width(4);
$line_dot->set_colour('#DFC329');
$line_dot->set_dot_size(5);
$line_dot->set_values($data_1);
$line_hollow = new OFC_Charts_Line_Hollow();
$line_hollow->set_width(1);
$line_hollow->set_colour('#6363AC');
$line_hollow->set_dot_size(5);
$line_hollow->set_values($data_2);
$line = new OFC_Charts_Line();
$line->set_width(1);
$line->set_colour('#5E4725');
$line->set_dot_size(5);
$line->set_values($data_3);
$y = new OFC_Elements_Axis_Y();
$y->set_range(0, 20, 5);
$chart = new OFC_Chart();
$chart->set_title(new OFC_Elements_Title('Three lines example'));
$chart->set_y_axis($y);
//
// here we add our data sets to the chart:
//
$chart->add_element($line_dot);
$chart->add_element($line_hollow);
$chart->add_element($line);
echo $chart->toPrettyString();
 /**
  * @Route("/{anno}/{mes}/panel_proyeccion_nuevos_ingresos_marco_data.json", name="panel_proyeccion_nuevos_ingresos_marco_data", defaults={"anno"="2013","mes"="01"}, options={"expose"=true})
  */
 public function panelProyeccionNuevosIngresosMarcoAction($anno, $mes)
 {
     include_once __DIR__ . "/../Util/OFC/OFC_Chart.php";
     $title = new \OFC_Elements_Title('Proyección ingresos por contratos marco ' . $anno);
     //Me conecto a la BD y pregunto por los ingresos del año:
     $ingresos = array();
     //El primer indice lo lleno con ceros:
     foreach ($this->meses as $key => $value) {
         $ingresos[] = 0;
     }
     $sql = "SELECT MONTH(date_closed) as MES, SUM( CASE 1 WHEN ( (DATEDIFF('" . $anno . "-12-31',opportunities_cstm.fecha_de_inicio_ejecucion_c) > 1) AND (opportunities_cstm.fecha_fin_contrato_c > '" . $anno . "-12-31')) THEN ROUND((amount * (DATEDIFF('" . $anno . "-12-31',opportunities_cstm.fecha_de_inicio_ejecucion_c)/DATEDIFF(opportunities_cstm.fecha_fin_contrato_c,opportunities_cstm.fecha_de_inicio_ejecucion_c))),2)    WHEN (DATEDIFF('" . $anno . "-12-31',opportunities_cstm.fecha_de_inicio_ejecucion_c) < 1) THEN 0  WHEN (DATEDIFF('" . $anno . "-12-31',opportunities_cstm.fecha_fin_contrato_c) > -1) THEN amount  END) as SUMA FROM opportunities INNER JOIN opportunities_cstm ON opportunities_cstm.id_c = opportunities.id WHERE deleted = 0 AND sales_stage = 'Closed Won' AND YEAR(date_closed) = " . $anno . " AND opportunities_cstm.contrato_marzo_c = 1  GROUP BY MES ORDER BY MES ASC;\n";
     $stmt = $this->container->get('doctrine')->getManager()->getConnection()->prepare($sql);
     $stmt->execute();
     foreach ($stmt->fetchAll() as $data) {
         $ingresos[$data["MES"] - 1] = (int) $data["SUMA"];
     }
     $ingresos = array_slice($ingresos, 0, $mes);
     $this->acumulate($ingresos);
     $line_dot = new \OFC_Charts_Line();
     $line_dot->set_values($ingresos);
     $line_dot->set_key("Ingresos", 10);
     $line_dot->set_width(1);
     $line_dot->set_colour('#FF0000');
     $line_dot->set_dot_size(3);
     //Me conecto a la BD y pregunto por la proyeccion del año:
     $proyecciones = array();
     //El primer indice lo lleno con ceros:
     foreach ($this->meses as $key => $value) {
         $proyecciones[] = 0;
     }
     $sql = "SELECT MONTH(date_closed) as MES, SUM( ( CASE 1 WHEN ( (DATEDIFF('" . $anno . "-12-31',opportunities_cstm.fecha_de_inicio_ejecucion_c) > 1) AND (opportunities_cstm.fecha_fin_contrato_c > '" . $anno . "-12-31')) THEN ROUND((amount * (DATEDIFF('" . $anno . "-12-31',opportunities_cstm.fecha_de_inicio_ejecucion_c)/DATEDIFF(opportunities_cstm.fecha_fin_contrato_c,opportunities_cstm.fecha_de_inicio_ejecucion_c))),2)    WHEN (DATEDIFF('" . $anno . "-12-31',opportunities_cstm.fecha_de_inicio_ejecucion_c) < 1) THEN 0  WHEN (DATEDIFF('" . $anno . "-12-31',opportunities_cstm.fecha_fin_contrato_c) > -1) THEN amount  END)  * IFNULL(probabiidad_adjudicacion_c/100,0) ) as SUMA FROM opportunities INNER JOIN opportunities_cstm ON opportunities_cstm.id_c = opportunities.id WHERE deleted = 0 AND sales_stage IN ('APROBADO','EN_ESTUDIO','PROSPECCION_CONTINGENTE','PROSPECCION_GENERAL') AND YEAR(date_closed) = " . $anno . "  AND opportunities_cstm.contrato_marzo_c = 1 GROUP BY MES ORDER BY MES ASC;\n";
     $stmt = $this->container->get('doctrine')->getManager()->getConnection()->prepare($sql);
     $stmt->execute();
     foreach ($stmt->fetchAll() as $data) {
         $proyecciones[$data["MES"] - 1] = (int) $data["SUMA"];
     }
     //La proyección del mes actual es la ultima de los ingresos.
     $proyecciones[$mes - 1] = $proyecciones[$mes - 1] + $ingresos[$mes - 1];
     $this->acumulate($proyecciones);
     $line_dot_proyeccion = new \OFC_Charts_Line();
     $line_dot_proyeccion->set_values($proyecciones);
     $line_dot_proyeccion->set_key("Estimado", 10);
     $line_dot_proyeccion->set_width(1);
     $line_dot_proyeccion->set_colour('#41DB00');
     $line_dot_proyeccion->set_dot_size(3);
     //Metas
     $sql = "SELECT enero,febrero,marzo,abril,mayo,junio,julio,agosto,septiembre,octubre,noviembre,diciembre FROM metas_metas WHERE anno = 2013 AND deleted = 0 AND anno = " . $anno . " and es_marco = 1 LIMIT 1";
     $stmt = $this->container->get('doctrine')->getManager()->getConnection()->prepare($sql);
     $stmt->execute();
     $metas = array(0 => 0);
     foreach ($stmt->fetchAll() as $data) {
         $metas[0] = (int) $data["enero"];
         $metas[1] = (int) $data["febrero"];
         $metas[2] = (int) $data["marzo"];
         $metas[3] = (int) $data["abril"];
         $metas[4] = (int) $data["mayo"];
         $metas[5] = (int) $data["junio"];
         $metas[6] = (int) $data["julio"];
         $metas[7] = (int) $data["agosto"];
         $metas[8] = (int) $data["septiembre"];
         $metas[9] = (int) $data["octubre"];
         $metas[10] = (int) $data["noviembre"];
         $metas[11] = (int) $data["diciembre"];
     }
     $line_dot_metas = new \OFC_Charts_Line();
     $line_dot_metas->set_values($metas);
     $line_dot_metas->set_key("Metas", 10);
     $line_dot_metas->set_width(1);
     $line_dot_metas->set_colour('#1240AB');
     $line_dot_metas->set_dot_size(3);
     $x = new \OFC_Elements_Axis_X();
     $x->set_labels_from_array($this->meses);
     $y = new \OFC_Elements_Axis_Y();
     $max_avg = max($ingresos);
     $max_avg = $max_avg > max($proyecciones) ? $max_avg : max($proyecciones);
     $max = $max_avg > max($metas) ? $max_avg : max($metas);
     $max = round($max * 1.25, -3);
     $y->set_range(0, $max, round($max / 4, 0));
     $chart = new \OFC_Chart();
     $chart->set_bg_colour('#FFFFFF');
     $chart->set_title($title);
     $chart->add_element($line_dot);
     $chart->add_element($line_dot_proyeccion);
     $chart->add_element($line_dot_metas);
     $chart->set_x_axis($x);
     $chart->set_y_axis($y);
     $response = new Response($chart->toPrettyString());
     $response->headers->set('Content-Type', 'application/json');
     return $response;
 }
예제 #6
0
 * Copyright (C) 2008 John Glazebrook <*****@*****.**>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * 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_LIBRARY_PATH . '/lib/OFC/OFC_Chart.php');

$title = new OFC_Elements_Title( date("D M d Y") );

$line_dot = new OFC_Charts_Line();
$line_dot->set_values( array(9,8,7,6,5,4,3,2,1) );

$chart = new OFC_Chart();
$chart->set_title( $title );
$chart->add_element( $line_dot );

echo $chart->toPrettyString();

예제 #7
0
 private function createGraph(Gpf_Chart_DataRecordSet $data)
 {
     if ($this->chartType == Gpf_Rpc_Chart::CHART_TYPE_LINE_DOT && $this->data1->getSize() > 150) {
         $this->chartType = Gpf_Rpc_Chart::CHART_TYPE_LINE;
     }
     switch ($this->chartType) {
         case Gpf_Rpc_Chart::CHART_TYPE_AREA:
             if ($data->getSize() > 40) {
                 $areaGraph = new OFC_Charts_Area_Line();
             } else {
                 $areaGraph = new OFC_Charts_Area_Hollow();
             }
             $areaGraph->set_width(3);
             $areaGraph->set_dot_size(3);
             $areaGraph->set_colour($data->getColor());
             $areaGraph->set_key($data->getName(), 10);
             $areaGraph->set_values($data->getValues());
             $areaGraph->set_tooltip($data->getTooltip());
             return $areaGraph;
         case Gpf_Rpc_Chart::CHART_TYPE_BAR_OUTLINE:
             $barGraph = new OFC_Charts_Bar();
             $barGraph->set_alpha(50);
             $barGraph->set_colour($data->getColor());
             $barGraph->set_key($data->getName(), 10);
             $barGraph->set_values($data->getValues());
             $barGraph->set_tooltip($data->getTooltip());
             return $barGraph;
         case Gpf_Rpc_Chart::CHART_TYPE_LINE_DOT:
             $lineDotGraph = new OFC_Charts_Line_Dot();
             $lineDotGraph->set_width(3);
             $lineDotGraph->set_dot_size(3);
             $lineDotGraph->set_colour($data->getColor());
             $lineDotGraph->set_key($data->getName(), 10);
             $lineDotGraph->set_values($data->getValues());
             $lineDotGraph->set_tooltip($data->getTooltip());
             return $lineDotGraph;
         default:
             $lineGraph = new OFC_Charts_Line();
             $lineGraph->set_width(3);
             $lineGraph->set_dot_size(3);
             $lineGraph->set_colour($data->getColor());
             $lineGraph->set_key($data->getName(), 10);
             $lineGraph->set_values($data->getValues());
             $lineGraph->set_tooltip($data->getTooltip());
             return $lineGraph;
     }
 }
예제 #8
0
/**
 * $array['title']
 * $array['legend_y']
 * $array['legend_x']
 * $array['values']
 * $array['values_key']
 * $array['range_max']
 * $array['range_step']
 * @param $array
 * @return unknown_type
 */
function create_chart_data($array)
{
    if (!$array) {
        return;
    }
    require_once 'OFC/OFC_Chart.php';
    $chart = new OFC_Chart();
    $chart->set_bg_colour('#ffffff');
    $title = new OFC_Elements_Title($array['title']);
    $title->set_style('{color: #567300; font-size: 16px; font-weight:bold;}');
    $chart->set_title($title);
    $yl = new OFC_Elements_Legend_Y($array['legend_y']);
    $yl->set_style('{font-size:18px;}');
    $chart->set_y_legend($yl);
    $xl = new OFC_Elements_Legend_X($array['legend_x']);
    $xl->set_style('{font-size:18px;color:#Ff0}');
    $chart->set_x_legend($xl);
    $elements = array();
    $colors = array('', '#CC00AA', '#9C48F0', '#b0de09', '#0d8ecf', '#ff6600', '#fcd202', '#E2EBFF', '#AAAAAA');
    foreach ($array['values'] as $k => $v) {
        ksort($v, SORT_STRING);
        $line = new OFC_Charts_Line();
        $line->set_key($array['values_key'][$k], 12);
        $colors[$k] ? $line->set_colour($colors[$k]) : '';
        $line->set_values(array_values($v));
        $default_dot = new OFC_Charts_Line_Dot();
        $default_dot->tooltip('#x_label#<br>#val#');
        $line->set_default_dot_style($default_dot);
        $elements[] = $line;
        $array['values'][$k] =& $v;
    }
    foreach ($elements as $element) {
        $chart->add_element($element);
    }
    $x = new OFC_Elements_Axis_X();
    $x->colour = '#909090';
    $x_axis_labels = new OFC_Elements_Axis_X_Label_Set();
    $x->set_steps($array['show_step']);
    $x_axis_labels->set_steps($array['show_step']);
    if (is_array($array['values'][0])) {
        $keys = array_keys($array['values'][0]);
    } else {
        $keys = array_keys($array['values']);
    }
    $x_axis_labels->set_labels($keys);
    $x_axis_labels->set_size(12);
    $x_axis_labels->set_colour('#Ff0');
    $x_axis_labels->set_rotate('-45');
    $x->set_labels($x_axis_labels);
    $chart->set_x_axis($x);
    $y = new OFC_Elements_Axis_Y();
    $range_min = isset($array['range_min']) ? $array['range_min'] : 0;
    $y->set_range($range_min, $array['range_max'], $array['range_step']);
    $chart->set_y_axis($y);
    return $chart->toPrettyString();
}