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; }
$data_2[] = sin($i) * 1.9 + 10; $data_3[] = sin($i) * 1.9 + 4; // just show to two decimal places // in our labels: //$labels[] = number_format($tmp,2); } $title = new OFC_Elements_Title(date("D M d Y")); $line_1 = new OFC_Charts_Line_Dot(); $line_1->set_values($data_1); $line_1->set_halo_size(0); $line_1->set_width(2); $line_1->set_dot_size(4); $line_2 = new OFC_Charts_Line_Dot(); $line_2->set_values($data_2); $line_2->set_halo_size(1); $line_2->set_width(1); $line_2->set_dot_size(4); $line_3 = new OFC_Charts_Line_Dot(); $line_3->set_values($data_3); $line_3->set_halo_size(1); $line_3->set_width(6); $line_3->set_dot_size(4); $y = new OFC_Elements_Axis_Y(); $y->set_range(0, 15, 5); $chart = new OFC_Chart(); $chart->set_title($title); $chart->add_element($line_1); $chart->add_element($line_2); $chart->add_element($line_3); $chart->set_y_axis($y); echo $chart->toPrettyString();
* 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'; // generate some random data srand((double) microtime() * 1000000); $data_1 = array(); $data_2 = array(); $data_3 = array(); 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();
/** * 最近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; }
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; } }
/** * $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(); }