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(); }
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; }
/** * $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(); }