Example #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');
	
	}
Example #2
0
 public function reg_data()
 {
     $_label = array('05-01', '05-02', '05-03', '05-04', '05-05', '05-06', '05-07', '05-08', '05-09', '05-10', '05-11', '05-12', '05-13', '05-14', '05-15');
     $_value = array(1235, 1125, 1323, 1389, 1256, 1568, 1383, 1677, 1953, 1798, 2089, 2215, 1738, 2189, 2315);
     $_max_value = 2500;
     $this->load->library('OFC_Chart');
     $title = new OFC_Elements_Title("日注册用户数(人)");
     //创建图表类型对象
     $element = new OFC_Charts_Bar_Glass();
     //设置图标值
     $element->set_values($_value);
     //$element->set_width( 2 );
     //$element->set_dot_style(array('type'=>"solid-dot",'dot-size'=>5,'halo-size'=>1,'colour'=>'#3D5C56'));
     //设置动画
     $element->set_on_show(array('type' => "pop-up", 'cascade' => 0.8, 'delay' => 0.1));
     $element->set_colour("#009829");
     //创建图表对象
     $chart = new OFC_Chart();
     $chart->set_title($title);
     //图表类型添加到图表
     $chart->add_element($element);
     //x轴
     $x_axis = new OFC_Elements_Axis_X();
     $x_axis->set_labels(array('labels' => $_label));
     $x_axis->set_steps(1);
     $chart->set_x_axis($x_axis);
     //y轴
     $y_axis = new OFC_Elements_Axis_Y();
     $y_axis->set_range(0, $_max_value, $_max_value / 10);
     $chart->set_y_axis($y_axis);
     //x 脚标
     $x_legend = new OFC_Elements_Legend_X('日期');
     $x_legend->set_style('{font-size: 20px; color: #778877}');
     $chart->set_x_legend($x_legend);
     $chart->set_bg_colour('#ffffff');
     echo $chart->toPrettyString();
 }
Example #3
0
 public function draw_summary_chart($gb_captions)
 {
     $f = $this->init_module(Libs_OpenFlashChart::module_name());
     //row summary numeric
     $f2 = $this->init_module(Libs_OpenFlashChart::module_name());
     //row summary currency
     $fc = $this->init_module(Libs_OpenFlashChart::module_name());
     //columns summary numeric
     $fc2 = $this->init_module(Libs_OpenFlashChart::module_name());
     //columns summary currency
     $title = new OFC_Elements_Title("Summary by row");
     $f->set_title($title);
     $f2->set_title($title);
     if (!empty($this->categories)) {
         $labels = array();
         $labels_c = array();
         foreach ($this->categories as $q => $c) {
             if ($this->format[$c] == 'currency') {
                 $labels_c[] = strip_tags($c);
             } else {
                 $labels[] = strip_tags($c);
             }
         }
         $x_ax = new OFC_Elements_Axis_X();
         $x_ax->set_labels_from_array($labels);
         $f->set_x_axis($x_ax);
         $x_ax = new OFC_Elements_Axis_X();
         $x_ax->set_labels_from_array($labels_c);
         $f2->set_x_axis($x_ax);
     }
     $title = new OFC_Elements_Title("Summary by column");
     $fc->set_title($title);
     $fc2->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);
     $fc->set_x_axis($x_ax);
     $fc2->set_x_axis($x_ax);
     $max = 5;
     $max2 = 5;
     $maxc = 5;
     $maxc2 = 5;
     $curr = false;
     $num = false;
     $col_total = array();
     $color = 0;
     foreach ($this->ref_records as $k => $r) {
         $results = call_user_func($this->display_cell_callback, $r);
         $ref_rec = call_user_func($this->ref_record_display_callback, $r, true);
         $bar = new OFC_Charts_Bar_Glass();
         $bar->set_colour(self::$colours[$color % count(self::$colours)]);
         $color++;
         $bar->set_key(strip_tags($ref_rec), 10);
         if (empty($this->categories)) {
             $total = 0;
             $i = 0;
             foreach ($results as &$res_ref) {
                 if (is_array($res_ref)) {
                     $res_ref = array_pop($res_ref);
                 }
                 $val = strip_tags($res_ref);
                 $total += $val;
                 if (!isset($this->cols_total[$i])) {
                     $this->cols_total[$i] = array();
                 }
                 $this->cols_total[$i][0] += $val;
                 $i++;
             }
             $bar->set_values(array($total));
             if ($this->format == 'currency') {
                 if ($total > $max2) {
                     $max2 = $total;
                 }
                 $f2->add_element($bar);
                 $curr = true;
             } else {
                 if ($total > $max) {
                     $max = $total;
                 }
                 $f->add_element($bar);
                 $num = true;
             }
         } else {
             $bar_c = new OFC_Charts_Bar_Glass();
             $bar_c->set_colour(self::$colours[$color % count(self::$colours)]);
             $bar_c->set_key(strip_tags($ref_rec), 10);
             $arr = array();
             $arr_c = array();
             foreach ($this->categories as $q => $c) {
                 $total = 0;
                 if (!isset($this->cols_total[$c])) {
                     $this->cols_total[$c] = array();
                 }
                 $i = 0;
                 foreach ($results as $v) {
                     if (is_array($v[$c])) {
                         $v[$c] = reset($v[$c]);
                     }
                     $val = (double) strip_tags($v[$c]);
                     $total += $val;
                     if (!isset($this->cols_total[$c][$i])) {
                         $this->cols_total[$c][$i] = 0;
                     }
                     $this->cols_total[$c][$i] += $val;
                     $i++;
                 }
                 if ($this->format[$c] == 'currency') {
                     $arr_c[] = $total;
                     if ($max2 < $total) {
                         $max2 = $total;
                     }
                 } else {
                     $arr[] = $total;
                     if ($max < $total) {
                         $max = $total;
                     }
                 }
             }
             if (!empty($arr)) {
                 $bar->set_values($arr);
                 $f->add_element($bar);
                 $num = true;
             }
             if (!empty($arr_c)) {
                 $bar_c->set_values($arr_c);
                 $f2->add_element($bar_c);
                 $curr = true;
             }
         }
     }
     if ($num) {
         $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);
         print '<br>';
     }
     if ($curr) {
         $y_ax = new OFC_Elements_Axis_Y();
         $y_ax->set_range(0, $max2);
         $y_ax->set_steps($max2 / 10);
         $f2->set_y_axis($y_ax);
         $f2->set_width(950);
         $f2->set_height(400);
         $this->display_module($f2);
         print '<br>';
     }
     if (empty($this->categories)) {
         $bar = new OFC_Charts_Bar_Glass();
         $bar->set_colour(self::$colours[0]);
         $bar->set_key('Total', 10);
         $mm = 5;
         $values = array();
         foreach ($this->cols_total as $val) {
             $rval = $val[0];
             if ($mm < $rval) {
                 $mm = $rval;
             }
             $values[] = $rval;
         }
         $bar->set_values($values);
         if ($this->format == 'currency') {
             $maxc2 = $mm;
             $fc2->add_element($bar);
         } else {
             $maxc = $mm;
             $fc->add_element($bar);
         }
     } else {
         $i = 0;
         foreach ($this->cols_total as $k => $arr) {
             $bar = new OFC_Charts_Bar_Glass();
             $bar->set_colour(self::$colours[$i % count(self::$colours)]);
             $bar->set_key(strip_tags($k), 10);
             $bar->set_values($arr);
             $mm = 5;
             foreach ($arr as $val) {
                 if ($mm < $val) {
                     $mm = $val;
                 }
             }
             if ($this->format[$k] == 'currency') {
                 if ($mm > $maxc2) {
                     $maxc2 = $mm;
                 }
                 $fc2->add_element($bar);
             } else {
                 if ($mm > $maxc) {
                     $maxc = $mm;
                 }
                 $fc->add_element($bar);
             }
             $i++;
         }
     }
     if ($num) {
         $y_ax = new OFC_Elements_Axis_Y();
         $y_ax->set_range(0, $maxc);
         $y_ax->set_steps($maxc / 10);
         $fc->set_y_axis($y_ax);
         $fc->set_width(950);
         $fc->set_height(400);
         $this->display_module($fc);
         print '<br>';
     }
     if ($curr) {
         $y_ax = new OFC_Elements_Axis_X();
         $y_ax->set_range(0, $maxc2);
         $y_ax->set_steps($maxc2 / 10);
         $fc2->set_y_axis($y_ax);
         $fc2->set_width(950);
         $fc2->set_height(400);
         $this->display_module($fc2);
         print '<br>';
     }
 }
Example #4
0
<?php

/**
 * PHP Integration of Open Flash Chart
 * 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/OFC_Chart.php';
$title = new OFC_Elements_Title(date("D M d Y"));
$bar = new OFC_Charts_Bar_Glass();
$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->toString();