Esempio n. 1
0
 public function __construct()
 {
     $this->data1 = null;
     $this->data2 = null;
     $this->chart = new OFC_Chart();
     $this->chart->set_bg_colour('#FFFFFF');
     $title = new OFC_Elements_Title('');
     $title->set_style('font-size: 14px;');
     $this->setTitle($title);
 }
 public function listsAction()
 {
     $title = new OFC_Elements_Title('测试统计');
     $title->setStyle('{font-size: 16px;}');
     $start = strtotime(date('Y-m-d', strtotime('-30 days')));
     $l = array();
     for ($i = 0; $i <= 30; $i++) {
         $l[] = date('m/d', $start + $i * 86400);
     }
     $labels = new OFC_Elements_Axis_Label($l);
     $labels->setRotate(30);
     $x = new OFC_Elements_Axis_X();
     $x->setLabels($labels)->setGridColour('#EAF4FB');
     $data1 = array();
     $data2 = array();
     for ($i = 0; $i <= 30; $i++) {
         //            $s = $this->db->select()
         //                ->from('order_info', 'sum(order_amount)')
         //                ->where('order_status = 1')
         //                ->where('add_time >= ?', $start)
         //                ->where('add_time < ?', $start + 86400);
         //                ->fetchOne();
         $data1[] = $i;
         //            $s = $this->db->select()
         //                ->from('order_info', 'sum(order_amount)')
         //                ->where('order_status = 1')
         //                ->where('pay_status = 2 OR shipping_status = 1 OR shipping_status = 2')
         //                ->where('add_time >= ?', $start)
         //                ->where('add_time < ?', $start + 86400)
         //                ->fetchOne();
         //            $data2[] = $s ? floatval($s) : 0;
         $data2[] = $i + rand(200, 1000);
         $start += 86400;
     }
     $y = new OFC_Elements_Axis_Y();
     $max = max(20000, max($data1) + 1000);
     $y->setRange(0, $max, floor($max / 20000) * 1000)->setGridColour('#EAF4FB');
     $line1 = new OFC_Charts_Line_Dot();
     $line1->setKey('总数', 12)->setValues($data1)->setTip('#x_label# 总数 ¥#val#');
     $line2 = new OFC_Charts_Line_Dot();
     $line2->setColour('#FF0000')->setKey('变化的数据', 12)->setValues($data2)->setTip('#x_label# 变化 ¥#val#');
     $chart = new OFC_Chart();
     $chart->setTitle($title)->setXaxis($x)->setYaxis($y)->setBgColour('#FEFFFF')->addElement($line1)->addElement($line2)->output();
     $this->isload = false;
 }
Esempio n. 3
0
 /**
  * 最近30天浏览统计
  */
 public function action_month()
 {
     $uname = $this->getQuery('save_dir');
     //$stat_date = urldecode($this->getRequest('stat_date', 'stat_date'));
     //$end_date = urldecode($this->getRequest('end_date', 'end_date'));
     $title = new OFC_Elements_Title($uname . '最近30日流量统计');
     $title->setStyle('{font-size: 16px;}');
     $start = strtotime(date('Y-m-d', strtotime('-30 days')));
     $l = array();
     for ($i = 0; $i <= 30; $i++) {
         $l[] = date('m/d', $start + $i * 86400);
         $listDay[] = date('y-m-d', $start + $i * 86400);
     }
     $labels = new OFC_Elements_Axis_Label($l);
     $labels->setRotate(30);
     $x = new OFC_Elements_Axis_X();
     $x->setLabels($labels)->setGridColour('#EAF4FB');
     $data1 = array();
     $data2 = array();
     foreach ($listDay as $i) {
         $time = date('Y-m-d', strtotime($i));
         $tot_flow = DB::select('tot_flow')->from('imgup_flow')->where('uname', '=', $uname)->where('date', '=', $time)->fetch_one();
         $s1 = $tot_flow / 1048576;
         $data1[] = $s1 ? round($s1) : 0;
         $s2 = DB::select('tot_times')->from('imgup_flow')->where('uname', '=', $uname)->where('date', '=', $time)->fetch_one();
         $s2 = $s2;
         $data2[] = $s2 ? floatval($s2) : 0;
         $start += 86400;
     }
     $y = new OFC_Elements_Axis_Y();
     $max = max(2000, max($data2) + 100);
     $y->setRange(0, $max, floor($max / 2000) * 100)->setGridColour('#EAF4FB');
     $line1 = new OFC_Charts_Line_Dot();
     $line1->setKey('流量', 12)->setValues($data1)->setTip('#x_label# 访问 #val# m');
     $line2 = new OFC_Charts_Line_Dot();
     $line2->setColour('#FF0000')->setKey('访问次数', 12)->setValues($data2)->setTip('#x_label# 访问 #val# 次');
     $chart = new OFC_Chart();
     $chart->setTitle($title)->setXaxis($x)->setYaxis($y)->setBgColour('#FEFFFF')->addElement($line1)->addElement($line2)->output();
     $this->auto_render = false;
 }
 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());
 }
Esempio n. 5
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") );
$title->set_style( '{color: #567300; font-size: 14px}' );

$bar = new OFC_Charts_Bar_Sketch( '#81AC00', '#567300', 5 );
$bar->set_values( array(9,8,7,6,5,4,3,2,1) );

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

echo $chart->toPrettyString();
Esempio n. 6
0
File: Ofc.php Progetto: Aeryris/grid
    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;
    }
Esempio n. 7
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();
}