예제 #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
 function OFC_Charts_Line_Hollow()
 {
     parent::OFC_Charts_Line();
     $this->type = 'line_hollow';
 }
예제 #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
for ($i = 0; $i < 9; $i++) {
    $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);
 function OFC_Charts_Line_Dot()
 {
     parent::OFC_Charts_Line();
     $this->type = 'line_dot';
 }
예제 #6
0
파일: users.php 프로젝트: Kuzat/kofradia
    if ($day == $today) {
        break;
    }
}
$result = \Kofradia\DB::get()->query("SELECT DATE(FROM_UNIXTIME(up_created_time)) day, COUNT(up_id) count FROM users_players WHERE up_created_time >= {$expire} GROUP BY DATE(FROM_UNIXTIME(up_created_time))");
while ($row = $result->fetch()) {
    $stats_new[$row['day']] = (int) $row['count'];
}
$result = \Kofradia\DB::get()->query("SELECT DATE(FROM_UNIXTIME(up_deactivated_time)) day, COUNT(up_id) count FROM users_players WHERE up_deactivated_time >= {$expire} GROUP BY DATE(FROM_UNIXTIME(up_deactivated_time))");
while ($row = $result->fetch()) {
    $stats_die[$row['day']] = (int) $row['count'];
}
$ofc = new OFC();
$ofc->title(new OFC_Title("Antall spillere"));
$ofc->tooltip()->title("font-size: 13px;font-weight:bold");
$bar = new OFC_Charts_Line();
$bar->dot_style()->type("solid-dot")->dot_size(3)->halo_size(2)->tip("#x_label#<br>#val# nye brukere");
$bar->text("Antall nye spillere");
$bar->values(array_values($stats_new));
$bar->colour(OFC_Colours::$colours[0]);
$ofc->add_element($bar);
$bar = new OFC_Charts_Line();
$bar->dot_style()->type("solid-dot")->dot_size(3)->halo_size(2)->tip("#x_label#<br>#val# døde brukere");
$bar->text("Antall døde spillere");
$bar->values(array_values($stats_die));
$bar->colour(OFC_Colours::$colours[1]);
$ofc->add_element($bar);
$ofc->axis_x()->label()->steps(2)->rotate(330)->labels(array_keys($stats_new));
$ofc->axis_y()->set_numbers(0, max(max($stats_new), max($stats_die)));
$ofc->dark_colors();
$ofc->dump();
 /**
  * @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;
 }
예제 #8
0
파일: Area.php 프로젝트: rodrigorm/OFC
 function OFC_Charts_Area()
 {
     parent::OFC_Charts_Base();
     $this->type = 'area';
 }
예제 #9
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;
     }
 }
예제 #10
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();

예제 #11
0
$days = array();
$days_max = 0;
$users = array();
while ($row = $result->fetch()) {
    $users[$row['up_name']][$row['day']] = (int) $row['num_actions'];
    $days[$row['day']] = (isset($days[$row['day']]) ? (int) $days[$row['day']] : 0) + (int) $row['num_actions'];
    $days_max = max($days_max, $row['num_actions']);
}
// sorter statistikk
$stats = array();
foreach ($days as $day => $total) {
    foreach ($users as $user => $user_days) {
        $stats[$user][$day] = isset($user_days[$day]) ? $user_days[$day] : 0;
    }
}
$ofc = new OFC();
$c = new OFC_Colours();
$ofc->title(new OFC_Title("Aktivitet i crewloggen"));
$ofc->tooltip()->title("font-size: 13px;font-weight:bold");
foreach ($stats as $user => $days) {
    $bar = new OFC_Charts_Line();
    $bar->dot_style()->type("solid-dot")->dot_size(3)->halo_size(2)->tip("Antall registreringer #x_label# for {$user}: #val#");
    $bar->text($user);
    $bar->values(array_values($days));
    $bar->colour($c->pick());
    $ofc->add_element($bar);
}
$ofc->axis_x()->label()->rotate(340)->labels(array_keys($days))->steps(5);
$ofc->axis_y()->set_numbers(0, min(20, $days_max));
$ofc->dark_colors();
$ofc->dump();
예제 #12
0
파일: pokernum.php 프로젝트: Kuzat/kofradia
$result = \Kofradia\DB::get()->query("\n\tSELECT DATE(FROM_UNIXTIME(poker_time_start)) AS day, COUNT(IF(poker_winner = 0, 1, NULL)) num_uavgjort,\n\t\tCOUNT(IF((poker_winner = 1 AND poker_starter_up_id = up_id) OR (poker_winner = 2 AND poker_challenger_up_id = up_id), 1, NULL)) num_wins,\n\t\tCOUNT(IF((poker_winner = 1 AND poker_starter_up_id = up_id) OR (poker_winner = 2 AND poker_challenger_up_id = up_id), NULL, 1)) num_loss\n\tFROM poker, users_players\n\tWHERE poker_time_start >= {$time_start} AND poker_time_start <= {$time_end} AND up_u_id = {$u_id} AND (up_id = poker_starter_up_id OR up_id = poker_challenger_up_id) AND poker_state = 4\n\tGROUP BY DATE(FROM_UNIXTIME(poker_time_start))");
$max = 0;
while ($row = $result->fetch()) {
    $stats_wins[$row['day']] = (int) $row['num_wins'];
    $stats_loss[$row['day']] = (int) $row['num_loss'];
    $stats_u[$row['day']] = (int) $row['num_uavgjort'];
}
$ofc = new OFC();
$ofc->title(new OFC_Title("Pokerstatistikk for {$up_name} siste 30 dager"));
$bar = new OFC_Charts_Line();
$bar->text("Antall vunnet");
$bar->dot_style()->type("solid-dot")->dot_size(3)->halo_size(2)->tip("#x_label#<br>Vunnet #val# runder");
$bar->values(array_values($stats_wins));
$bar->colour(OFC_Colours::$colours[2]);
$ofc->add_element($bar);
$bar = new OFC_Charts_Line();
$bar->text("Antall tapt");
$bar->dot_style()->type("solid-dot")->dot_size(3)->halo_size(2)->tip("#x_label#<br>Tapt #val# runder");
$bar->values(array_values($stats_loss));
$bar->colour(OFC_Colours::$colours[0]);
$ofc->add_element($bar);
$bar = new OFC_Charts_Line();
$bar->text("Antall uavgjort");
$bar->dot_style()->type("solid-dot")->dot_size(3)->halo_size(2)->tip("#x_label#<br>#val# runder uavgjort");
$bar->values(array_values($stats_u));
$bar->colour(OFC_Colours::$colours[1]);
$ofc->add_element($bar);
$ofc->axis_x()->label()->steps(2)->rotate(330)->labels(array_keys($stats_wins));
$ofc->axis_y()->set_numbers(0, max(max($stats_wins), max($stats_loss), max($stats_u)));
$ofc->dark_colors();
echo $ofc;
예제 #13
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();
}
예제 #14
0
 /**
  * 构造函数
  */
 public function __construct()
 {
     parent::__construct();
     $this->type = 'line_hollow';
 }
예제 #15
0
파일: chart.php 프로젝트: rorteg/fengoffice
function create_chart_data_object($type, $y_values_array)
{
    switch ($type) {
        case 'line':
            $data_object = new OFC_Charts_Line();
            if (array_var($y_values_array, 'color')) {
                $data_object->set_colour(array_var($y_values_array, 'color'));
            }
            if (array_var($y_values_array, 'dot_size')) {
                $data_object->set_dot_size(array_var($y_values_array, 'dot_size'));
            }
            if (array_var($y_values_array, 'halo_size')) {
                $data_object->set_halo_size(array_var($y_values_array, 'halo_size'));
            }
            if (array_var($y_values_array, 'text')) {
                $data_object->set_key(array_var($y_values_array, 'text', ''), array_var($y_values_array, 'text_size', 10));
            }
            if (array_var($y_values_array, 'width')) {
                $data_object->set_width(array_var($y_values_array, 'width'));
            }
            $values_data = array_var($y_values_array, 'values', array());
            break;
        case 'bar':
            $data_object = new OFC_Charts_Bar_3d();
            if (array_var($y_values_array, 'color')) {
                $data_object->set_colour(array_var($y_values_array, 'color'));
            }
            if (array_var($y_values_array, 'tooltip')) {
                $data_object->set_tooltip(array_var($y_values_array, 'tooltip'));
            }
            if (array_var($y_values_array, 'text')) {
                $data_object->set_key(array_var($y_values_array, 'text', ''), array_var($y_values_array, 'text_size', 10));
            }
            if (array_var($y_values_array, 'alpha')) {
                $data_object->set_alpha(array_var($y_values_array, 'alpha'));
            }
            $values_data = array_var($y_values_array, 'values', array());
            break;
        case 'bar-stack':
            $data_object = new OFC_Charts_Bar_Stack();
            if (array_var($y_values_array, 'color')) {
                $data_object->set_colour(array_var($y_values_array, 'color'));
            }
            if (array_var($y_values_array, 'colors')) {
                $data_object->{'colours'} = array_var($y_values_array, 'colors');
            }
            if (array_var($y_values_array, 'keys')) {
                $data_object->{'keys'} = array_var($y_values_array, 'keys');
            }
            if (array_var($y_values_array, 'tooltip')) {
                $data_object->set_tooltip(array_var($y_values_array, 'tooltip'));
            }
            if (array_var($y_values_array, 'text')) {
                $data_object->set_key(array_var($y_values_array, 'text', ''), array_var($y_values_array, 'text_size', 10));
            }
            if (array_var($y_values_array, 'alpha')) {
                $data_object->set_alpha(array_var($y_values_array, 'alpha'));
            }
            $data = array_var($y_values_array, 'values', array());
            foreach ($data as $d) {
                $data_object->append_stack($d);
            }
            break;
        default:
            continue;
    }
    if (isset($values_data)) {
        $data_object->set_values($values_data);
    }
    return $data_object;
}
예제 #16
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());
 }
예제 #17
0
파일: panel.php 프로젝트: Kuzat/kofradia
 /**
  * Opprett OFC-linje
  */
 protected function stats_ofc_line($ofc, $text, $tip, $values, $color)
 {
     $bar = new OFC_Charts_Line();
     $bar->text($text);
     $bar->dot_style()->type("solid-dot")->dot_size(3)->halo_size(2)->tip($tip);
     $bar->values($values);
     $bar->colour($color);
     $ofc->add_element($bar);
 }