function get_statistic() { $this->load->library('OpenFlashChartLib', NULL, 'OFCL'); $data_1 = array(); $data_2 = array(); // generate 7 data points for ($i = 0; $i <= 7; $i++) { $x = mktime(0, 0, 0, date("m"), date("d") - $i, date('Y')); $param['sms_date'] = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d") - $i, date("Y"))); $param['user_id'] = $this->session->userdata('id_user'); $y = $this->Kalkun_model->get_sms_used('date', $param); $data_1[] = new scatter_value($x, $y); $data_2[] = $y; } $def = new solid_dot(); $def->size(4)->halo_size(0)->colour('#21759B')->tooltip('#date:d M y#<br>#val# SMS'); $line = new scatter_line('#21759B', 3); $line->set_values($data_1); $line->set_default_dot_style($def); $line->set_key("SMS used in last 7 days", 10); $x = new x_axis(); // grid line and tick every 10 $x->set_range(mktime(0, 0, 0, date("m"), date("d") - 7, date('Y')), mktime(0, 0, 0, date("m"), date("d"), date('Y'))); // show ticks and grid lines for every day: $x->set_steps(86400); $labels = new x_axis_labels(); // tell the labels to render the number as a date: $labels->text('#date:M-d#'); // generate labels for every day $labels->set_steps(86400); // only display every other label (every other day) $labels->visible_steps(1); $labels->rotate(45); // finally attach the label definition to the x axis $x->set_labels($labels); $y = new y_axis(); if (max($data_2) > 0) { $max = max($data_2); } else { $max = 10; } $y->set_range(0, $max, 10); $chart = new open_flash_chart(); //$chart->set_title( $title ); $chart->add_element($line); $chart->set_x_axis($x); $chart->set_y_axis($y); echo $chart->toPrettyString(); }
/** * Method to render a statistical chart using Open Flash library. * * @return false if someting wrong */ function render() { $values = array(); foreach ($this->values as $number_variable => $variable) { $values[$number_variable] = (int) $variable; } $area = new area(); $area->set_default_dot_style(new hollow_dot()); $area->set_colour('#5B56B6'); $area->set_fill_alpha(0.4); $area->set_values($values); $area->set_key('Values', 12); $x_labels = new x_axis_labels(); $x_labels->set_steps(1); $x_labels->set_vertical(); $x_labels->set_colour('#A2ACBA'); $x_labels->set_labels($this->legend); $x = new x_axis(); $x->set_colour('#A2ACBA'); $x->set_grid_colour('#D7E4A3'); $x->set_offset(false); $x->set_steps(1); // Add the X Axis Labels to the X Axis $x->set_labels($x_labels); $y = new y_axis(); $y_max = max($values) > 0 ? max($values) : 4; $y_mod = (int) ($y_max / 4 + 1); $y_max += $y_mod - $y_max % $y_mod; $y->set_range(0, $y_max, $y_mod); $y->labels = null; $y->set_offset(false); $chart = new open_flash_chart(); $chart->set_x_axis($x); $chart->add_y_axis($y); $chart->add_element($area); return $chart; }
$y_labels = array(); $max_value = 0; foreach ($data as $label => $value) { if ($max_value < $value) { $max_value = $value; } $y_labels[] = (string) $label; $hbar->append_value(new hbar_value(0, (double) $value)); } $chart = new open_flash_chart(); $chart->set_title($title); $chart->add_element($hbar); $step_count = $max_value > 0 ? $max_value / 10 : 1; $x = new x_axis(); $x->set_offset(false); $x->set_steps($max_value / 10); $chart->set_x_axis($x); $y = new y_axis(); $y->set_offset(true); $y->set_labels($y_labels); $chart->add_y_axis($y); if (isset($yaxis_label)) { $y_legend = new y_legend($yaxis_label); $y_legend->set_style('{font-size: 20px; color: #000000}'); $chart->set_y_legend($y_legend); } if (isset($xaxis_label)) { $x_legend = new x_legend($xaxis_label); $x_legend->set_style('{font-size: 20px; color: #000000}'); $chart->set_x_legend($x_legend); }
function getNewUsersByTime($timePhase, $fromDate = '', $toDate = '') { $this->load->library('ofc'); $userId = $this->common->getUserId(); $this->ofc->open_flash_chart(); $this->ofc->set_bg_colour(CHART_BG_COLOR); $toTime = date("Y-m-d", strtotime("-1 day")); if ($timePhase == "7day") { $fromTime = date("Y-m-d", strtotime("-8 day")); $color = CHART_LINE_1; $key = "近7日新增用户"; $title = new title("近7日新增用户统计"); } if ($timePhase == "1month") { $title = new title("近30天新增用户统计"); $fromTime = date("Y-m-d", strtotime("-31 day")); $color = CHART_LINE_2; $key = "近30天新增用户统计"; } if ($timePhase == "3month") { $title = new title("近三个月新增用户统计"); $fromTime = date("Y-m-d", strtotime("-92 day")); $color = CHART_LINE_3; $key = "近三个月新增用户统计"; } if ($timePhase == "all") { $title = new title("所有新增用户统计"); $fromTime = '1970-01-01'; $color = CHART_LINE_4; $key = "所有新增用户统计"; } if ($timePhase == "any") { $title = new title("所有新增用户统计"); $fromTime = $fromDate; $toTime = $toDate; $color = CHART_LINE_4; $key = "所有新增用户统计"; } $fromTime = $this->product->getUserStartDate($userId, $fromTime); $query = $this->newusermodel->getNewUsersByUserId($fromTime, $toTime, $userId); $data = array(); $maxY = 0; $recordCount = $query->num_rows(); $steps = $recordCount - 1 <= 10 ? 2 : (int) (((int) $recordCount - 1) / 10); $xlabelArray = array(); if ($query != null && $query->num_rows() > 0) { foreach ($query->result() as $row) { $dot = new dot(); $dot->size(3)->halo_size(1)->colour($color); $dot->tooltip($row->startdate . " 新增" . $row->totalusers . "用户"); $dot->value((int) $row->totalusers); if ((int) $row->totalusers > $maxY) { $maxY = (int) $row->totalusers; } array_push($xlabelArray, date('y-m-d', strtotime($row->startdate))); array_push($data, $dot); } } $y = new y_axis(); $y->set_range(0, $this->common->getMaxY($maxY), $this->common->getStepY($maxY)); $x = new x_axis(); $x->set_range(0, $recordCount > 1 ? $recordCount - 1 : 1); $x_labels = new x_axis_labels(); $x_labels->set_steps($steps); $x_labels->set_vertical(); $x_labels->set_colour(CHART_LABEL_COLOR); $x_labels->set_size(13); $x_labels->set_labels($xlabelArray); $x_labels->rotate(-25); $x->set_labels($x_labels); $x->set_steps(1); $this->ofc->set_y_axis($y); $this->ofc->set_x_axis($x); $dot = new dot(); $dot->size(3)->halo_size(1)->colour($color); $line = new line(); $line->set_default_dot_style($dot); $line->set_values($data); $line->set_width(2); $line->set_colour($color); $line->colour($color); $line->set_key($key, 12); $this->ofc->add_element($line); $title->set_style("{font-size: 14px; color:#000000; font-family: Verdana; text-align: center;}"); // $x_legend = new x_legend("<a href=\"javascript:changeChartName('chartNewUser')\">新增用户</a> <a href=\"javascript:changeChartName('chartActiveUser')\">活跃用户</a> <a href=\"javascript:changeChartName('chartStartUser')\">启动用户</a>"); // $this->ofc->set_x_legend( $x_legend ); // $x_legend->set_style( '{font-size: 14px; color: #778877}' ); $this->ofc->set_title($title); echo $this->ofc->toPrettyString(); }
rsort($maxima); $maximum = $maxima[0]; //-----/end get ranges ----------------- // Prepare the x-axis $x = new x_axis(); $x->set_range($lowest, $highest); // Calculate the steps and visible steps $step = ($highest - $lowest) / 60; $step_vis = 2; // do not allow steps to be less than 30 minutes if ($step < 26400) { # 86400 $step = 26400; $step_vis = 1; } $x->set_steps($step); $labels = new x_axis_labels(); $labels->text('#date:Y-m-d#'); $labels->set_steps($step); $labels->visible_steps($step_vis); $labels->rotate(90); $x->set_labels($labels); // Prepare the y-axis $y = new y_axis(); // $maximum is already set above // set the range and y-step $y->set_range(0, $maximum + getIdealYSteps($maximum)); $y->set_steps(getIdealYSteps($maximum)); # $chart->add_element( $s ); $chart->set_x_axis($x); $chart->add_y_axis($y);
public function get_jx_json_bar($info, $type = '') { $year = array_keys($info); $price = array_values($info); $chart = new open_flash_chart(); $chart->set_bg_colour('#FFFFFF'); //flash背景颜色 $x_labels = new x_axis_labels(); $x_labels->set_steps(1); $x_labels->set_size(12); $x_labels->set_colour('#000000'); if (count($year) > 0) { $x_labels->set_vertical(); } $x_labels->set_labels($year); // // 插入数据 $x = new x_axis(); $x->set_colour('#000000'); $x->set_grid_colour('#dadada'); $x->set_offset(true); $x->set_steps(1); // Add the X Axis Labels to the X Axis $x->set_labels($x_labels); $x->set_offset(true); $chart->set_x_axis($x); // $bar = new bar_filled( '#74b1e0', '#9dc7e8' ); // $bar->set_values( $price ); $price_array = array(); foreach ($price as $k => $v) { $price_array[$k] = new bar_value($v); $price_array[$k]->set_colour('#74b1e0'); if ($type == 'percent') { //$y->set_label_text("#val#%"); $price_array[$k]->set_tooltip($year[$k] . '<br>' . '' . number_format($v) . '%'); } else { $price_array[$k]->set_tooltip($year[$k] . '<br>' . '' . number_format($v)); } } $bar = new bar_glass(); $bar->set_values($price_array); $chart->add_element($bar); // // LOOK: // //$x_legend = new x_legend( '1983 to 2008' ); //$x_legend->set_style( '{font-size: 20px; color: #778877}' ); //$chart->set_x_legend( $x_legend ); // // remove this when the Y Axis is smarter // $y = new y_axis(); $max = $this->get_the_right_y(max($price)); $max = $max > 0 ? $max : 1; $y->set_range(0, ($max / 5 + 1) * 5, $max / 5 + 1); // if ($max > 20 && $max <= 100) { // // $y->set_range(0, $max, 10); // }elseif($max >= 10&&$max<=20){ // $y->set_range(0, $max, 5); // } // else { // $y->set_range(0, $max); // } $y->set_colour('#000000'); $y->set_grid_colour('#dadada'); if ($type == 'percent') { $y->set_label_text(" #val#%"); } else { $y->set_label_text(" #val#"); } $chart->add_y_axis($y); $info = $chart->toPrettyString(); return $info; }
function admin_graphs($id = null) { App::import('Vendor', 'Newsletter.php-ofc-library', array('file' => 'php-ofc-library/open-flash-chart.php')); //Configure::write('debug', 0); //$this->layout = null; // generate some random data srand((double) microtime() * 1000000); $title = new title(__d("newsletter", "Views per time", true)); $chart = new open_flash_chart(); $chart->set_title($title); $newsletter = $this->Newsletter->read(null, $id); // Views $dates = array(); $values = array(); //// init sender class //// App::import('Lib', 'Newsletter.ClassCollection'); $senderOpt = NewsletterConfig::load('sender'); if (!is_array($senderOpt)) { $senderOpt = array('name' => $senderOpt); } $sender = ClassCollection::getObject('NewsletterSender', $senderOpt['name']); //// query //// $opt = array('type' => 'graph', 'query' => array('fields' => array('count(*) as nb', 'DATE(NewsletterEvent.date) as date'), 'conditions' => array('NewsletterSended.newsletter_id' => $id, 'or' => array('NewsletterEvent.action' => 'view', array('NewsletterEvent.action IS NULL', 'NewsletterEvent.url' => null))), 'group' => 'DATE(NewsletterEvent.date)', 'order' => 'DATE(NewsletterEvent.date)', 'model' => 'NewsletterEvent')); $data = $this->_get_stats(array('viewByDays' => $opt), $newsletter, $sender); //debug($data); $dates = $data['viewByDays']; $min_value = 99999999; $max_value = 0; foreach ($dates as $d => $val) { if ($val < $min_value) { $min_value = $val; } if ($val > $max_value) { $max_value = $val; } } if ($max_value == $min_value) { $max_value++; $min_value--; } $min_value = 0; //debug($dates); $min_date = key($dates); end($dates); $max_date = key($dates); for ($cur_date = $min_date; $cur_date <= $max_date; $cur_date = $cur_date + 86400) { $x = strtotime('00:00:00', $cur_date); if (isset($dates[$cur_date])) { $values[] = new scatter_value($x, $dates[$cur_date]); } else { $values[] = new scatter_value($x, 0); } } if ($max_date == $min_date) { $max_date += 86400; } //debug($values); //pr($views); $line_dot = new line(); $line_dot->set_values($values); $line_dot->set_text("Views"); $chart->add_element($line_dot); $y = new y_axis(); $y->set_range($min_value, $max_value, ($max_value - $min_value) / 10); $x = new x_axis(); // grid line and tick every 10 $x->set_range(mktime(0, 0, 0, date("m", $min_date), date("d", $min_date), date("Y", $min_date)), mktime(0, 0, 0, date("m", $max_date), date("d", $max_date), date("Y", $max_date))); // show ticks and grid lines for every day: $x->set_steps(86400); $labels = new x_axis_labels(); // tell the labels to render the number as a date: $labels->text('#date:d-m-Y#'); // generate labels for every day $labels->set_steps(86400); // only display every other label (every other day) $labels->visible_steps(ceil(($max_date - $min_date) / 86400 / 20)); $labels->rotate(90); $x->set_labels($labels); $chart->set_x_axis($x); $chart->set_y_axis($y); $chart->set_bg_colour("#FFFFFF"); //print_r($views); //$this->set("allviews",$views[0][0]['count(*)']); $line_dot = new line(); $line_dot->set_values(array(2, 1)); $line_dot->set_text("Unique views"); $line_dot->colour("#0000000"); //$chart->add_element($line_dot); // echo $chart->toPrettyString(); exit; //$this->render(false); }
function _render_statistic($x = array(), $yout = array(), $yin = array(), $type = 'bar', $points) { $this->load->helper('date'); $this->load->library('OpenFlashChartLib', NULL, 'OFCL'); $data_1 = array(); $data_2 = array(); $data_3 = array(); switch ($type) { case 'bar': for ($i = 0; $i <= $points; $i++) { $data_1[$i] = $x[$i]; $data_2[$i] = (int) $yout[$i]; // force to integer $data_3[$i] = (int) $yin[$i]; // force to integer } $data_1 = array_reverse($data_1); $data_2 = array_reverse($data_2); $data_3 = array_reverse($data_3); $bar_1 = new bar(); $bar_1->set_values($data_3); $bar_1->set_colour('#639F45'); $bar_1->key(lang('kalkun_incoming_sms'), 10); $bar_1->set_tooltip('#x_label#<br>#val# SMS'); //$bar_1->set_key("SMS used in last 7 days", 10); $bar_2 = new bar(); $bar_2->set_values($data_2); $bar_2->set_colour('#21759B'); $bar_2->key(lang('kalkun_outgoing_sms'), 10); $bar_2->set_tooltip('#x_label#<br>#val# SMS'); $x = new x_axis(); $labels = new x_axis_labels(); $labels->set_labels($data_1); $labels->set_steps(1); $x->set_labels($labels); $y = new y_axis(); $max = max(max($data_2), max($data_3)); if ($max < 10) { $max = 10; } $max = ceil($max / 5) * 5; $range = ceil($max / 5); $range = ceil($range / 10) * 10; $y->set_range(0, $max, $range); $element1 = $bar_1; $element2 = $bar_2; break; case 'line': for ($i = 0; $i <= 7; $i++) { $data_1[$i] = new scatter_value($x[$i], $yin[$i]); $data_2[$i] = new scatter_value($x[$i], $yout[$i]); $data_3[$i] = (int) $yin[$i]; $data_4[$i] = (int) $yout[$i]; } $def = new solid_dot(); $def->size(4)->halo_size(0)->colour('#21759B')->tooltip('#date:d M y#<br>#val# SMS'); $line_1 = new scatter_line('#639F45', 3); $line_1->set_values($data_1); $line_1->set_default_dot_style($def); $line_1->set_key("Incoming SMS", 10); $line_2 = new scatter_line('#21759B', 3); $line_2->set_values($data_2); $line_2->set_default_dot_style($def); $line_2->set_key("Outgoing SMS", 10); $x = new x_axis(); // grid line and tick every 10 $x->set_range(mktime(0, 0, 0, date("m"), date("d") - 7, date('Y')), mktime(0, 0, 0, date("m"), date("d"), date('Y'))); // show ticks and grid lines for every day: $x->set_steps(86400); $labels = new x_axis_labels(); // tell the labels to render the number as a date: $labels->text('#date:M-d#'); // generate labels for every day $labels->set_steps(86400); // only display every other label (every other day) $labels->visible_steps(1); $labels->rotate(45); // finally attach the label definition to the x axis $x->set_labels($labels); $y = new y_axis(); $max = max(max($data_3), max($data_4)); if ($max < 1) { $max = 10; } $y->set_range(0, $max, round($max / 100) * 10); $element1 = $line_1; $element2 = $line_2; break; } $chart = new open_flash_chart(); $chart->add_element($element1); $chart->add_element($element2); $chart->set_x_axis($x); $chart->set_y_axis($y); echo $chart->toPrettyString(); }
$chart->set_title($title); */ $chart->add_element($area); $chart->add_element($area2); $chart->add_element($area3); $chart->add_element($candle); $x_labels = new x_axis_labels(); $x_labels->set_steps(1); $x_labels->rotate(30); //ROTATE GRAPH LABELS //$x_labels->set_vertical(); $x_labels->set_labels($period_label); $x = new x_axis(); $x->set_grid_colour('#D7E4A3'); $x->set_offset($period_offset); $x->set_steps(1); // Add the X Axis Labels to the X Axis $x->set_labels($x_labels); $chart->set_x_axis($x); // // LOOK: // $x_legend = new x_legend("{$period_start} to {$period_end}"); $x_legend->set_style('{font-size: 20px; }'); $chart->set_x_legend($x_legend); // // remove this when the Y Axis is smarter // $y = new y_axis(); $y->set_range($range_min_value, $range_max_value, $range_step); $chart->add_y_axis($y);
function netio() { function bit_to_kb($n) { return round($n / 1000, 2); } function bit_to_mb($n) { return round($n / 1000000, 2); } function get_data() { $recv_l = trim(shell_exec("cat /sys/class/net/eth0/statistics/rx_bytes")) / 8; sleep(1); $recv_n = trim(shell_exec("cat /sys/class/net/eth0/statistics/rx_bytes")) / 8; return $recv_n - $recv_l; } if (array_key_exists('netio', $_SESSION) && array_key_exists('recv_l', $_SESSION)) { if (count($_SESSION['netio']) == 10) { array_shift($_SESSION['netio']); $_SESSION['netio'][] = get_data(); } else { $_SESSION['netio'][] = get_data(); $_SESSION['recv_l'] = end($_SESSION['netio']); } } else { $_SESSION['netio'] = array(0, 0, 0, 0, 0, 0, 0, 0, 0); $_SESSION['netio'][] = get_data(); $_SESSION['recv_l'] = end($_SESSION['netio']); } $data = $_SESSION['netio']; /* $data = array(); for($i=0;$i<40;$i++){ $data[] = rand(1000000,10000000); } */ foreach (range(1, 10) as $i) { settype($i, 'string'); $second[] = $i; } if (max($data) <= 1000) { $data = array_map("bit_to_kb", $data); $y_axis_max = 1; $y_axis_key_text = " KB/s"; } elseif (max($data) <= 10000) { $data = array_map("bit_to_kb", $data); $y_axis_max = 10; $y_axis_key_text = " KB/s"; } elseif (max($data) <= 100000) { $data = array_map("bit_to_kb", $data); $y_axis_max = 100; $y_axis_key_text = " KB/s"; } elseif (max($data) <= 1000000) { $data = array_map("bit_to_kb", $data); $y_axis_max = 1000; $y_axis_key_text = " KB/s"; } elseif (max($data) <= 10000000) { $data = array_map("bit_to_mb", $data); $y_axis_max = 10; $y_axis_key_text = " MB/s"; } else { $data = array_map("bit_to_mb", $data); $y_axis_max = 100; $y_axis_key_text = " MB/s"; } $y_axis_step = $y_axis_max / 5; $chart = new open_flash_chart(); $title = new title("实时流量显示"); $title->set_style("{font-size: 12px; color: #A2ACBA; text-align: center;}"); $chart->set_title($title); #点是指曲线图上的顶点 # $d = new dot(); # $d->colour('#9C0E57')->size(3); $area = new area(); #width是指曲线的宽度 # $area->set_width(3); # $area->set_default_dot_style($d); $area->set_colour('#5B56B6'); #value即曲线顶的值 $area->set_values($data); #左上角的文字 $area->set_key($y_axis_key_text, 10); $area->set_fill_colour('#CCCAAA'); #设透明度 $area->set_fill_alpha(0.3); #area设置结束,使用add_element方法把area加进来 $chart->add_element($area); $chart->set_bg_colour('#FFFFFF'); #设置label $x_labels = new x_axis_labels(); $x_labels->set_steps(1); $x_labels->set_colour('#A2ACBA'); $x_labels->set_labels($second); #设置X轴 $x_axis = new x_axis(); $x_axis->set_colour('#A2ACBA'); $x_axis->set_grid_colour('#D7E4A3'); $x_axis->set_offset(false); $x_axis->set_steps(1); $x_axis->set_labels($x_labels); $chart->set_x_axis($x_axis); #设置X轴的文件说明,即x_legend $legend_text = "当前网络流量 " . end($data) . $y_axis_key_text; $x_legend = new x_legend($legend_text); $x_legend->set_style('{font-size: 12px; color: #778877}'); $chart->set_x_legend($x_legend); #设置轴 $y_axis = new y_axis(); $y_axis->set_range(0, $y_axis_max, $y_axis_step); $y_axis->labels = null; $y_axis->set_offset(false); $chart->add_y_axis($y_axis); header("Cache-Control: cache, must-revalidate"); header("Pragma: public"); echo $chart->toPrettyString(); }
function render_service_reports() { $content = "<h1>Service Reports</h1>"; // Start Filter for service type $allServiceTypes = ServiceType::get_service_types(); # $allServiceTypes = array('all' => 'all'); #$allServiceTypes = array_merge($allServiceTypes, ServiceType::get_service_types()); $allServiceTypes['all'] = 'all'; $service_type = $_GET['service_type']; $service_filter = $_GET['service_type']; if ($service_type == '' || !isset($service_type) || !is_numeric($service_type)) { $service_type = 'all'; $service_filter = ''; } $filter = "\r\n\t\t<FORM>\r\n\t\t<DIV style=\" \">\r\n\t\t<SELECT name'=service_type_report'\r\n\t\t\tonChange=\"window.location='services.php?&action=serviceReports&service_type='+this.options[this.selectedIndex].value;\">"; foreach ($allServiceTypes as $id => $name) { if ($service_type == $id) { $selected = "SELECTED"; } else { $selected = ''; } $filter .= "<OPTION value='{$id}' {$selected}>{$name}\n"; } $filter .= "\r\n\t\t</SELECT>\r\n\t\t</DIV>\r\n\t\t</FORM>\r\n\t"; // End filter $max_date = strtotime("2009-01-01"); $start_date = date("Y-m") . "-01"; // Get all months since start $workdate = strtotime($start_date); $now = strtotime("Now"); $form = new Form(auto, 3); $headings = array("Period", "In production", "Out of Production"); $data = array(); $x_ax_data = array(); $y_ax_data = array(); $handlers = array(); while ($workdate > $max_date) { $sql_enddate = date("Y-m-d", $workdate); $month_period = date("m-Y", $workdate); // This is for the chart $month_label = date("M\nY", $workdate); $graph_date = strtotime("-1 month", $workdate); $month_label = date("M\nY", $graph_date); $sql_startdate = date("Y-m-d", $workdate); array_push($x_ax_data, $month_label); array_push($y_ax_data, count(Service::get_inprod_services_at_date($sql_startdate, $service_filter))); // Add one month $workdate = strtotime("-1 month", $workdate); $sql_startdate = date("Y-m-d", $workdate); $out_of_prod = count(Service::get_outprod_services_diff_date($sql_startdate, $sql_enddate, $service_filter)); $in_prod = count(Service::get_inprod_services_diff_date($sql_startdate, $sql_enddate, $service_filter)); array_push($data, "{$sql_startdate} {$sql_enddate}"); array_push($data, $in_prod); array_push($data, $out_of_prod); array_push($handlers, "handleEvent('services.php?action=detailedServiceReports&start_date={$sql_startdate}&end_date={$sql_enddate}&service_type={$service_type}')"); } $form->setTableWidth("224px"); $form->setData($data); $form->setEventHandler($handlers); $form->setHeadings($headings); $form->setSortable(true); $content .= "<div style=\"float: left; clear: both; margin-right:28px\">" . $form->showForm() . "</div>"; // Chart // // This is the MODEL section: // include 'open-flash-chart/php-ofc-library/open-flash-chart.php'; // create an X Axis object // $y_ax_data = array_reverse($y_ax_data); $x_ax_data = array_reverse($x_ax_data); $x = new x_axis(); $x->set_steps(3); $x->set_labels_from_array($x_ax_data); $max = max($y_ax_data); $y = new y_axis(); $y->set_range(0, $max); // Bar $bar = new bar(); $bar->set_values($y_ax_data); // Bar // ------- LINE 2 ----- $line_2_default_dot = new dot(); $line_2_default_dot->size(3)->halo_size(1)->colour('#3D5C56'); $line_2 = new line(); $line_2->set_default_dot_style($line_2_default_dot); $line_2->set_values($y_ax_data); $line_2->set_width(3); $line_2->set_colour('#3D5C56'); $chart = new open_flash_chart(); $title = new title("In Production Services over Time"); $title->set_style("{font-size: 10px; font-family: Times New Roman; font-weight: bold; color: #000; text-align: center;}"); $chart->set_bg_colour('#FFFFFF'); $chart->set_title($title); $chart->add_element($bar); //$chart->add_element( $line1 ); $chart->add_element($line_2); $chart->set_x_axis($x); $chart->set_y_axis($y); // // This is the VIEW section: // Should print this first. // $heading = "\r\n\t<script type='text/javascript' src='open-flash-chart/js/json/json2.js'></script>\r\n\t<script type='text/javascript' src='open-flash-chart/js/swfobject.js'></script>\r\n\t<script type='text/javascript'>\r\n\tswfobject.embedSWF('open-flash-chart/open-flash-chart.swf', 'my_chart', '660', '350', '9.0.0');\r\n\t</script>\r\n\r\n\t<script type='text/javascript'>\r\n\r\n\tfunction open_flash_chart_data() {\r\n\t\treturn JSON.stringify(data);\r\n\t}\r\n\r\n\tfunction findSWF(movieName) {\r\n \t\tif (navigator.appName.indexOf('Microsoft')!= -1) {\r\n \t\t\treturn window[movieName];\r\n \t\t} else {\r\n \t\t\treturn document[movieName];\r\n \t\t}\r\n\t}\r\n \r\n\tvar data = " . $chart->toPrettyString() . "\r\n\r\n\t</script>\r\n\r\n\r\n\t<script type=\"text/javascript\">\r\n \r\n\tOFC = {};\r\n \r\n\tOFC.jquery = {\r\n \tname: 'jQuery',\r\n \tversion: function(src) { return \$('#'+ src)[0].get_version() },\r\n \trasterize: function (src, dst) { \$('#'+ dst).replaceWith(OFC.jquery.image(src)) },\r\n \timage: function(src) { return \"<img src='data:image/png;base64,\" + \$('#'+src)[0].get_img_binary() + \"' />\"},\r\n \tpopup: function(src) {\r\n var img_win = window.open('', 'Charts: Export as Image')\r\n with(img_win.document) {\r\n write('<html><head><title>Charts: Export as Image<\\/title><\\/head><body>' + OFC.jquery.image(src) + '<\\/body><\\/html>') }\r\n\t\t// stop the 'loading...' message\r\n\t\timg_win.document.close();\r\n \t}\r\n\t}\r\n \r\n\t// Using_ an object as namespaces is JS Best Practice. I like the Control.XXX style.\r\n\t//if (!Control) {var Control = {}}\r\n\t//if (typeof(Control == \"undefined\")) {var Control = {}}\r\n\tif (typeof(Control == \"undefined\")) {var Control = {OFC: OFC.jquery}}\r\n \r\n \r\n\t// By default, right-clicking on OFC and choosing \"save image locally\" calls this function.\r\n\t// You are free to change the code in OFC and call my wrapper (Control.OFC.your_favorite_save_method)\r\n\t// function save_image() { alert(1); Control.OFC.popup('my_chart') }\r\n\tfunction save_image() { alert(\"Your image will be displayed in a new window\"); OFC.jquery.popup('my_chart') }\r\n\t</script>\r\n\t<div id='my_chart' style='float:left; margin-left:28px;'></div>\r\n\t"; print " {$content}\n \r\n\t\t<div style=''<b>Select Service Type:</b>{$filter} <br></div>\n\r\n\t\t{$heading} "; }
function siremis_get_chart_data($groupId, $chartId, $debug = 0) { global $g_BizSystem; $cgobj = $g_BizSystem->GetService("ser.service.siremisCharts"); $cgrp = $cgobj->GetChartGroup($groupId); if ($debug == 1) { echo "Chart found {$id} :: " . $cgobj->GetChartGroupCount() . " ::: "; } $chart = $cgrp->GetChart($chartId); if (!$chart) { echo "Chart not found {$id}\n"; exit; } if ($debug == 1) { echo "Chart :: " . $cgrp->GetChartCount() . " ::: "; } $sql = "SELECT * "; $xydata = array(); // XAxis $xax = $chart->GetXAxisList(); foreach ($xax as $it) { $sql = "SELECT " . $it->GetXYData(); $xydata[0] = $it; } // YAxis $yax = $chart->GetYAxisList(); $yn = 0; foreach ($yax as $it) { $sql .= "," . $it->GetXYData(); $yn = $yn + 1; $xydata[$yn] = $it; } if ($debug == 1) { echo "::::::: {$yn} ::: " . $chart->GetYAxisCount(); } $sql .= " FROM " . $chart->GetTable(); if ($chart->GetOrderBy() && $chart->GetOrderBy() != "") { $sql .= " " . $chart->GetOrderBy(); } if ($chart->GetLimit() && $chart->GetLimit() != "") { $sql .= " " . $chart->GetLimit(); } // " ORDER BY id DESC LIMIT 30"; $db = $g_BizSystem->GetDBConnection("Serdb"); $resultSet = $db->query($sql); if ($resultSet === false) { $err = $db->ErrorMsg(); echo $err; exit; } $xdata = array(); $ydata = array(); for ($i = 0; $i < $yn; $i = $i + 1) { $ydata[$i] = array(); } $k = 0; $ymin = 0; $ymax = 0; while ($row = $resultSet->fetch()) { $xdata[$k] = $row[0]; for ($i = 0; $i < $yn; $i = $i + 1) { $ydata[$i][$k] = 0 + $row[$i + 1]; if ($k == 0) { $ymin = $ydata[$i][$k]; $ymax = $ydata[$i][$k]; } else { if ($ydata[$i][$k] < $ymin) { $ymin = $ydata[$i][$k]; } if ($ydata[$i][$k] > $ymax) { $ymax = $ydata[$i][$k]; } } } $k = $k + 1; } $ofcobj = new open_flash_chart(); $ctitle = $chart->GetTitle(); $rev = 0; if ($chart->GetOrder() && $chart->GetOrder() == "reverse") { $rev = 1; } $x = new x_axis(); $xstep = (int) ($k / 20); if ($k % 20 != 0) { $xstep = $xstep + 1; } $x->set_steps($xstep); if ($xydata[0]->getXYType() == "timestamp") { if ($rev == 1) { $time_min = $xdata[$k - 1]; $time_max = $xdata[0]; } else { $time_min = $xdata[0]; $time_max = $xdata[$k - 1]; } $ctitle .= " - From " . date('Y-m-d H:i:s', $time_min); $ctitle .= " To " . date('Y-m-d H:i:s', $time_max); $time_x_labels = new x_axis_labels(); $time_x_labels->rotate(20); $chart_lbls = array(); for ($i = 0; $i < $k; $i = $i + 1) { if ($rev == 0) { $chart_lbls[] = date('H:i', $xdata[$i]); } else { $chart_lbls[] = date('H:i', $xdata[$k - $i - 1]); } } $time_x_labels->visible_steps($xstep); $time_x_labels->set_labels($chart_lbls); $x->set_labels($time_x_labels); } else { $time_x_labels->visible_steps($xstep); if ($rev == 1) { $ctitle .= " - From " . $xdata[$k - 1] . " To " . $xdata[0]; } else { $ctitle .= " - From " . $xdata[0] . " To " . $xdata[$k - 1]; } } $ofcobj->set_title(new title($ctitle)); $dot_style = new dot(); $dot_style->size(3)->halo_size(1); for ($i = 0; $i < $yn; $i++) { if ($chart->GetChartType() == "area") { $line[$i] = new area(); $line[$i]->set_fill_alpha(0.3); $line[$i]->set_default_dot_style($dot_style); } else { if ($chart->GetChartType() == "line_dot") { $line[$i] = new line_dot(); $line[$i]->set_default_dot_style($dot_style); } else { $line[$i] = new line(); $line[$i]->set_default_dot_style($dot_style); } } if ($xydata[$i + 1]->GetXYColor() && $xydata[$i + 1]->GetXYColor() != "") { $line[$i]->set_colour($xydata[$i + 1]->GetXYColor()); } if ($xydata[$i + 1]->GetXYTitle() && $xydata[$i + 1]->GetXYTitle() != "") { $line[$i]->set_key($xydata[$i + 1]->GetXYTitle(), 10); } else { $line[$i]->set_key("Key " . $i, 10); } if ($rev == 1) { $line[$i]->set_values(array_reverse($ydata[$i])); } else { $line[$i]->set_values($ydata[$i]); } $ofcobj->add_element($line[$i]); } if ($ymax > 10) { $y = new y_axis(); if ($ymin > 10) { $y->set_range($ymin - 10, $ymax, (int) (($ymax - $ymin + 10) / 10)); } else { $y->set_range(0, $ymax, (int) ($ymax / 10)); } $ofcobj->set_y_axis($y); } $ofcobj->set_x_axis($x); if ($chart->GetBGColor() && $chart->GetBGColor() != "") { $ofcobj->set_bg_colour($chart->GetBGColor()); } // return $ofcobj->toPrettyString(); return $ofcobj->toString(); }
protected function renderHTML() { global $g_BizSystem; include_once MODULE_PATH . '/ser/config/cms.ChartsStatsAccCfg.php'; $fetchInterval = $cfg_stats_acc_fetch_interval; $sql = "SELECT method, sip_code, time, UNIX_TIMESTAMP(time) as tstamp FROM acc WHERE DATE_SUB(NOW(), INTERVAL " . $fetchInterval . " HOUR) <= time"; $db = $g_BizSystem->GetDBConnection("Serdb"); $resultSet = $db->query($sql); if ($resultSet === false) { $err = $db->ErrorMsg(); echo $err; exit; } $chart_colors = array(); $chart_colors[0] = '#FF0000'; $chart_colors[1] = '#00FF00'; $chart_colors[2] = '#0000FF'; $chart_colors[3] = '#408080'; $chart_colors[4] = '#330000'; $chart_colors[5] = '#FDD017'; $chart_colors[6] = '#52D017'; $chart_colors[7] = '#6698FF'; $chart_colors[8] = '#00FFFF'; $chart_colors[9] = '#FF00FF'; $chart_colors[10] = '#2554C7'; $chart_colors[11] = '#806D7E'; $chart_colors[12] = '#FF8040'; $chart_colors[13] = '#C0C0C0'; $chart_colors[14] = '#808000'; $chart_colors[15] = '#800000'; $chart_colors_size = 16; $acc_records = array(); $acc_records['invite'] = array(); $acc_records['bye'] = array(); $acc_records['message'] = array(); $acc_records['other'] = array(); $acc_records['invite200'] = array(); $acc_records['invite404'] = array(); $acc_records['invite487'] = array(); $acc_records['inviteXYZ'] = array(); for ($i = 0; $i <= $fetchInterval; $i++) { $acc_records['invite'][$i] = 0; $acc_records['bye'][$i] = 0; $acc_records['message'][$i] = 0; $acc_records['other'][$i] = 0; $acc_records['invite200'][$i] = 0; $acc_records['invite404'][$i] = 0; $acc_records['invite487'][$i] = 0; $acc_records['inviteXYZ'][$i] = 0; } $ymax = 0; $ymin = 0xfffffff; $yidx = 0; $ousr = 0; $ctime = time(); $stime = $ctime - 3600 * $fetchInterval; while ($row = $resultSet->fetch()) { $r_method = $row[0]; $r_sip_code = $row[1]; $r_time = $row[2]; $r_tstamp = $row[3]; $idx = (int) (($r_tstamp - $stime) / 3600); /* method stats */ if (isset($r_method)) { if ($r_method == "INVITE") { $acc_records['invite'][$idx] = $acc_records['invite'][$idx] + 1; if ($r_sip_code == "200") { $acc_records['invite200'][$idx] = $acc_records['invite200'][$idx] + 1; } else { if ($r_sip_code == "404") { $acc_records['invite404'][$idx] = $acc_records['invite404'][$idx] + 1; } else { if ($r_sip_code == "487") { $acc_records['invite487'][$idx] = $acc_records['invite487'][$idx] + 1; } else { $acc_records['inviteXYZ'][$idx] = $acc_records['inviteXYZ'][$idx] + 1; } } } } else { if ($r_method == "BYE") { $acc_records['bye'][$idx] = $acc_records['bye'][$idx] + 1; } else { if ($r_method == "MESSAGE") { $acc_records['message'][$idx] = $acc_records['message'][$idx] + 1; } else { $acc_records['other'][$idx] = $acc_records['other'][$idx] + 1; } } } } $yidx = $yidx + 1; } /* sip method types chart */ $mtsobj = new open_flash_chart(); $ctitle = "SIP Method Types"; $x = new x_axis(); $xstep = (int) ($fetchInterval / 12); if ($fetchInterval % 2 != 0) { $xstep = $xstep + 1; } $x->set_steps($xstep); $time_min = $stime; $time_max = $ctime; $ctitle .= " - From " . date('Y-m-d H:i:s', $time_min); $ctitle .= " To " . date('Y-m-d H:i:s', $time_max); $time_x_labels = new x_axis_labels(); $time_x_labels->rotate(20); $chart_lbls = array(); for ($i = 0; $i < $fetchInterval; $i = $i + 1) { $chart_lbls[] = date('H:i', $stime + 3600 * $i); } $time_x_labels->visible_steps($xstep); $time_x_labels->set_labels($chart_lbls); $x->set_labels($time_x_labels); $mtsobj->set_title(new title($ctitle)); $dot_style = new dot(); $dot_style->size(3)->halo_size(1); $clr = 0; $i = 0; $line[$i] = new line(); $line[$i]->set_default_dot_style($dot_style); $line[$i]->set_colour($chart_colors[$clr++ % $chart_colors_size]); $line[$i]->set_key("INVITE", 10); $line[$i]->set_values($acc_records['invite']); $mtsobj->add_element($line[$i]); $i++; $line[$i] = new line(); $line[$i]->set_default_dot_style($dot_style); $line[$i]->set_colour($chart_colors[$clr++ % $chart_colors_size]); $line[$i]->set_key("BYE", 10); $line[$i]->set_values($acc_records['bye']); $mtsobj->add_element($line[$i]); $i++; if ($cfg_stats_acc_message) { $line[$i] = new line(); $line[$i]->set_default_dot_style($dot_style); $line[$i]->set_colour($chart_colors[$clr++ % $chart_colors_size]); $line[$i]->set_key("MESSAGE", 10); $line[$i]->set_values($acc_records['message']); $mtsobj->add_element($line[$i]); $i++; } if ($cfg_stats_acc_other) { $line[$i] = new line(); $line[$i]->set_default_dot_style($dot_style); $line[$i]->set_colour($chart_colors[$clr++ % $chart_colors_size]); $line[$i]->set_key("OTHER", 10); $line[$i]->set_values($acc_records['other']); $mtsobj->add_element($line[$i]); $i++; } $val = max($acc_records['invite']); if ($ymax < $val) { $ymax = $val; } $val = max($acc_records['bye']); if ($ymax < $val) { $ymax = $val; } if ($cfg_stats_acc_message) { $val = max($acc_records['message']); if ($ymax < $val) { $ymax = $val; } } if ($cfg_stats_acc_other) { $val = max($acc_records['other']); if ($ymax < $val) { $ymax = $val; } } $val = min($acc_records['invite']); if ($ymin > $val) { $ymin = $val; } $val = min($acc_records['bye']); if ($ymin > $val) { $ymin = $val; } if ($cfg_stats_acc_message) { $val = min($acc_records['message']); if ($ymin > $val) { $ymin = $val; } } if ($cfg_stats_acc_other) { $val = min($acc_records['other']); if ($ymin > $val) { $ymin = $val; } } if ($ymax > 10) { $y = new y_axis(); if ($ymin > 10) { $y->set_range($ymin - 10, $ymax, (int) (($ymax - $ymin + 10) / 10)); } else { $y->set_range(0, $ymax, (int) ($ymax / 10)); } $mtsobj->set_y_axis($y); } $mtsobj->set_x_axis($x); $mtsobj->set_bg_colour("#A0C0B0"); /* sip invites chart */ $ivsobj = new open_flash_chart(); $ctitle = "SIP INVITEs"; $ctitle .= " - From " . date('Y-m-d H:i:s', $time_min); $ctitle .= " To " . date('Y-m-d H:i:s', $time_max); $ivsobj->set_title(new title($ctitle)); $ymax = 0; $ymin = 0xfffffff; $i = 0; $line[$i] = new line(); $line[$i]->set_default_dot_style($dot_style); $line[$i]->set_colour($chart_colors[$clr++ % $chart_colors_size]); $line[$i]->set_key("200", 10); $line[$i]->set_values($acc_records['invite200']); $ivsobj->add_element($line[$i]); $i++; $line[$i] = new line(); $line[$i]->set_default_dot_style($dot_style); $line[$i]->set_colour($chart_colors[$clr++ % $chart_colors_size]); $line[$i]->set_key("404", 10); $line[$i]->set_values($acc_records['invite404']); $ivsobj->add_element($line[$i]); $i++; $line[$i] = new line(); $line[$i]->set_default_dot_style($dot_style); $line[$i]->set_colour($chart_colors[$clr++ % $chart_colors_size]); $line[$i]->set_key("487", 10); $line[$i]->set_values($acc_records['invite487']); $ivsobj->add_element($line[$i]); $i++; $line[$i] = new line(); $line[$i]->set_default_dot_style($dot_style); $line[$i]->set_colour($chart_colors[$clr++ % $chart_colors_size]); $line[$i]->set_key("XYZ", 10); $line[$i]->set_values($acc_records['inviteXYZ']); $ivsobj->add_element($line[$i]); $i++; $val = max($acc_records['invite200']); if ($ymax < $val) { $ymax = $val; } $val = max($acc_records['invite404']); if ($ymax < $val) { $ymax = $val; } $val = max($acc_records['invite487']); if ($ymax < $val) { $ymax = $val; } $val = max($acc_records['inviteXYZ']); if ($ymax < $val) { $ymax = $val; } $val = min($acc_records['invite200']); if ($ymin > $val) { $ymin = $val; } $val = min($acc_records['invite404']); if ($ymin > $val) { $ymin = $val; } $val = min($acc_records['invite487']); if ($ymin > $val) { $ymin = $val; } $val = min($acc_records['inviteXYZ']); if ($ymin > $val) { $ymin = $val; } if ($ymax > 10) { $y = new y_axis(); if ($ymin > 10) { $y->set_range($ymin - 10, $ymax, (int) (($ymax - $ymin + 10) / 10)); } else { $y->set_range(0, $ymax, (int) ($ymax / 10)); } $ivsobj->set_y_axis($y); } $ivsobj->set_x_axis($x); $ivsobj->set_bg_colour("#C0C0A0"); $sHTML = ''; $sHTML .= ' <div align="center"> <p><b>Processed ' . $yidx . ' records. <br />Timezone: ' . date_default_timezone_get() . ' </b></p> </div> '; if ($yidx > 0) { $sHTML .= ' <script type="text/javascript" src="' . APP_URL . '/js/swfobject.js"></script> <script type="text/javascript"> swfobject.embedSWF( "' . APP_URL . '/modules/ser/pages/open-flash-chart.swf", "div_chart_acc_methods", "600", "300", "9.0.0", "expressInstall.swf", {"get-data":"get_data_acc_methods"} ); swfobject.embedSWF( "' . APP_URL . '/modules/ser/pages/open-flash-chart.swf", "div_chart_acc_invites", "600", "300", "9.0.0", "expressInstall.swf", {"get-data":"get_data_acc_invites"} ); </script> '; $sHTML .= ' <br /> <div align="center"> <div id="div_chart_acc_methods"> </div> <br /> <br /> <div id="div_chart_acc_invites"> </div> <br /> <br /> </div> '; $sHTML .= ' <script type="text/javascript"> function get_data_acc_methods() { data = \'' . $mtsobj->toString() . '\'; return data; } function get_data_acc_invites() { data = \'' . $ivsobj->toString() . '\'; return data; } </script> '; } /* if $yidx */ return $sHTML; }
$line_tot->set_width(2); $line_tot->set_key('Gesamt (kWh)', 10); $line_tot->set_tooltip("#val# kWh"); $max = max(max($data_watt), $max_val) * 1.15; $y = new y_axis(); $y->set_range(0, $max, round($max * 0.1, -1)); $x_labels = new x_axis_labels(); $x_labels->set_vertical(); $x_labels->set_steps(6); $x_labels->set_colour('#333333'); $x_labels->set_labels($time_axis); $x = new x_axis(); $x->set_colour('#333333'); $x->set_grid_colour('#ffffff'); $x->set_offset(false); $x->set_steps(3); // Add the X Axis Labels to the X Axis $x->set_labels($x_labels); $chart = new open_flash_chart(); $chart->set_tooltip($tooltip); $chart->set_title($title); //$chart->add_element( $line_max ); $chart->add_element($line_watt); $chart->add_element($bars_curr); //$chart->add_element( $line_tot ); //$chart->add_element( $sline ); $chart->set_bg_colour('#ffffff'); $chart->set_y_axis($y); $chart->set_x_axis($x); echo $chart->toString(); }
if ($array['date'] < $lowest_date) { $lowest_date = $array['date']; } if ($array['date'] > $highest_date) { $highest_date = $array['date']; } } } // // create an X Axis object $x = new x_axis(); $x->set_grid_colour("#E3E3E3"); //$x->steps(3); //$x->set_labels_from_array($labels); // grid line and tick every day $x->set_steps(TIME_DAY); $labels = new x_axis_labels(); $label_a = array_reverse($label_a); $labels->set_labels($label_a); $labels->text('#date:M d#'); $labels->set_steps(TIME_DAY); $labels->visible_steps(1); $labels->rotate(90); // finally attach the label definition to the x axis $x->set_labels($labels); //$x->set_steps(TIME_DAY); //SMA 50 $sma50 = array(); $sma25 = array(); $sma15 = array(); $sma10 = array();
$title = new title('Last ' . $days . ' Days Sales Chart'); $title->set_style("{font-size:14px; font-weight:bold; padding:10px;}"); $chart = new open_flash_chart(); $chart->set_title($title); $area = new area(); $area->set_colour('#5B56B6'); $area->set_values(array_values($bar_values)); $area->set_key('Products', 12); $chart->add_element($area); //define x-axis $x_labels = new x_axis_labels(); $x_labels->set_steps(4); $x_labels->set_labels($period); $x = new x_axis(); $x->set_grid_colour('#D7E4A3'); //$x->set_offset($period_offset); $x->set_steps(4); // Add the X Axis Labels to the X Axis $x->set_labels($x_labels); $chart->set_x_axis($x); //define y-axis $y = new y_axis(); $range_min_value = 0; $range_max_value = max($bar_values); $y_data_step = ceil($range_max_value / $y_points); $y_data_step = $y_data_step - $y_data_step % 100; $range_max_value = ceil($range_max_value / $y_data_step) * $y_data_step; $y->set_range($range_min_value, $range_max_value, $y_data_step); $chart->add_y_axis($y); echo $chart->toPrettyString(); require_once 'confy_close.php';
function result_screen($mode = 'reg') { global $month_names; $page_title = "Statistic Center Results"; $page_detail = " "; // ----------------------------------------- if (!checkdate($_POST['to_month'], $_POST['to_day'], $_POST['to_year'])) { die("The 'Date To:' time is incorrect, please check the input and try again"); } if (!checkdate($_POST['from_month'], $_POST['from_day'], $_POST['from_year'])) { die("The 'Date From:' time is incorrect, please check the input and try again"); } // ----------------------------------------- $to_time = mktime(12, 0, 0, $_POST['to_month'], $_POST['to_day'], $_POST['to_year']); $from_time = mktime(12, 0, 0, $_POST['from_month'], $_POST['from_day'], $_POST['from_year']); // $sql_date_to = date("Y-m-d",$to_time); // $sql_date_from = date("Y-m-d",$from_time); $human_to_date = getdate($to_time); $human_from_date = getdate($from_time); // ----------------------------------------- if ($mode == 'reg') { $table = 'Registration Statistics'; $sql_table = 'users'; $sql_field = 'added'; $page_detail = "Showing the number of users registered. (Note: All times based on GMT)"; } else { if ($mode == 'rate') { $table = 'Rating Statistics'; $sql_table = 'ratings'; $sql_field = 'added'; $page_detail = "Showing the number of ratings. (Note: All times based on GMT)"; } else { if ($mode == 'post') { $table = 'Post Statistics'; $sql_table = 'posts'; $sql_field = 'added'; $page_detail = "Showing the number of posts. (Note: All times based on GMT)"; } else { if ($mode == 'msg') { $table = 'PM Sent Statistics'; $sql_table = 'messages'; $sql_field = 'added'; $page_detail = "Showing the number of sent messages. (Note: All times based on GMT)"; } else { if ($mode == 'torr') { $table = 'Torrent Statistics'; $sql_table = 'torrents'; $sql_field = 'added'; $page_detail = "Showing the number of Torrents. (Note: All times based on GMT)"; } else { if ($mode == 'bans') { $table = 'Ban Statistics'; $sql_table = 'bans'; $sql_field = 'added'; $page_detail = "Showing the number of Bans. (Note: All times based on GMT)"; } else { if ($mode == 'comm') { $table = 'Comment Statistics'; $sql_table = 'comments'; $sql_field = 'added'; $page_detail = "Showing the number of torrent Comments. (Note: All times based on GMT)"; } else { if ($mode == 'new') { $table = 'News Statistics'; $sql_table = 'news'; $sql_field = 'added'; $page_detail = "Showing the number of News Items added. (Note: All times based on GMT)"; } else { if ($mode == 'poll') { $table = 'Poll Statistics'; $sql_table = 'polls'; $sql_field = 'added'; $page_detail = "Showing the number of Polls added. (Note: All times based on GMT)"; } else { if ($mode == 'rqst') { $table = 'Request Statistics'; $sql_table = 'requests'; $sql_field = 'added'; $page_detail = "Showing the number of Requests made. (Note: All times based on GMT)"; } } } } } } } } } } switch ($_POST['timescale']) { case 'daily': $sql_date = "%w %U %m %Y"; $php_date = "F jS - Y"; // $sql_scale = "DAY"; break; case 'monthly': $sql_date = "%m %Y"; $php_date = "F Y"; // $sql_scale = "MONTH"; break; default: // weekly $sql_date = "%U %Y"; $php_date = " [F Y]"; // $sql_scale = "WEEK"; break; } $sortby = isset($_POST['sortby']) ? mysql_real_escape_string($_POST['sortby']) : ""; // $sortby = sqlesc($sortby); $sqlq = "SELECT UNIX_TIMESTAMP(MAX({$sql_field})) as result_maxdate,\n\t\t\t\t COUNT(*) as result_count,\n\t\t\t\t DATE_FORMAT({$sql_field},'{$sql_date}') AS result_time\n\t\t\t\t FROM {$sql_table}\n\t\t\t\t WHERE UNIX_TIMESTAMP({$sql_field}) > '{$from_time}'\n\t\t\t\t AND UNIX_TIMESTAMP({$sql_field}) < '{$to_time}'\n\t\t\t\t GROUP BY result_time\n\t\t\t\t ORDER BY {$sql_field} {$sortby}"; $res = @mysql_query($sqlq); $running_total = 0; $max_result = 0; $results = array(); if (mysql_num_rows($res)) { while ($row = mysql_fetch_assoc($res)) { if ($row['result_count'] > $max_result) { $max_result = $row['result_count']; } $running_total += $row['result_count']; $results[] = array('result_maxdate' => $row['result_maxdate'], 'result_count' => $row['result_count'], 'result_time' => $row['result_time']); } include 'chart/php-ofc-library/open-flash-chart.php'; foreach ($results as $pOOp => $data) { $counts[] = (int) $data['result_count']; if ($_POST['timescale'] == 'weekly') { $labes[] = "Week #" . strftime("%W", $data['result_maxdate']) . "\n" . date($php_date, $data['result_maxdate']); } else { $labes[] = date($php_date, $data['result_maxdate']); } } $title = new title($page_title . "\n" . ucfirst($_POST['timescale']) . " " . $table . " " . $human_from_date['mday'] . " " . $month_names[$human_from_date['mon']] . " " . $human_from_date['year'] . " to " . $human_to_date['mday'] . " " . $month_names[$human_to_date['mon']] . " " . $human_to_date['year']); $chart = new open_flash_chart(); $chart->set_title($title); $line_1 = new line_hollow(); $line_1->set_values($counts); $line_1->set_key($table . " | Total: " . $running_total, 12); $line_1->set_halo_size(1); $line_1->set_width(2); $line_1->set_colour('#0099FF'); $line_1->set_dot_size(5); $chart->add_element($line_1); $x_labels = new x_axis_labels(); $x_labels->set_steps(2); $x_labels->set_vertical(); $x_labels->set_colour('#000000'); $x_labels->set_size(12); $x_labels->set_labels($labes); $x = new x_axis(); $x->set_colours('#A2ACBA', '#ECFFAF'); $x->set_steps(2); $x->set_labels($x_labels); $chart->set_x_axis($x); $y = new y_axis(); $y->set_steps(2); $y->set_colour('#A2ACBA'); $y->set_range(0, max($counts) + 5, 50); $chart->add_y_axis($y); $cont = $chart->toPrettyString(); // toFile($_SERVER["DOCUMENT_ROOT"]."/chart/","chart.json",$cont,false); // unset($cont); $html = "<script type=\"text/javascript\" src=\"chart/js/json/json2.js\"></script>"; $html .= "<script type=\"text/javascript\" src=\"chart/js/swfobject.js\"></script>"; $html .= "<script type=\"text/javascript\">\n\n\t\t\t\tfunction open_flash_chart_data()\n\t\t\t\t{\n\t\t\t\treturn JSON.stringify(data);\n\t\t\t\t}\n\n\t\t\t\tfunction findSWF(movieName) {\n\t\t\t\t if (navigator.appName.indexOf(\"Microsoft\")!= -1) {\n\t\t\t\t\treturn window[movieName];\n\t\t\t\t } else {\n\t\t\t\t\treturn document[movieName];\n\t\t\t\t }\n\t\t\t\t}\n\n\t\t\t\tvar data = " . $cont . ";\n\n\t\t\t\t\t swfobject.embedSWF(\"chart/open-flash-chart.swf\", \"my_chart\", \"800\", \"" . (max($counts) * 5 < 200 ? "250" : (max($counts) * 5 > 400 ? "400" : max($counts) * 5)) . "\", \"9.0.0\", \"expressInstall.swf\", {\"loading\":\"Please wait while the stats are loaded!\"} );\n\t\t\t\t\t </script>"; $html .= "<div id=\"my_chart\"></div>"; } else { $html .= "No results found\n"; } print $html . "<br />"; }
include '../php-ofc-library/open-flash-chart.php'; $chart = new open_flash_chart(); $chart->set_title(new title('Area Chart')); // // Make our area chart: // $area = new area(); // set the circle line width: $area->set_width(2); $area->set_default_dot_style(new hollow_dot()); $area->set_colour('#838A96'); $area->set_fill_colour('#E01B49'); $area->set_fill_alpha(0.4); $area->set_values($data); // add the area object to the chart: $chart->add_element($area); $y_axis = new y_axis(); $y_axis->set_range(-2, 2, 2); $y_axis->labels = null; $y_axis->set_offset(false); $x_axis = new x_axis(); $x_axis->labels = $data; $x_axis->set_steps(2); $x_labels = new x_axis_labels(); $x_labels->set_steps(4); $x_labels->set_vertical(); // Add the X Axis Labels to the X Axis $x_axis->set_labels($x_labels); $chart->add_y_axis($y_axis); $chart->x_axis = $x_axis; echo $chart->toPrettyString();
function get_linear_graph($dates, $vals, $keys = array()) { include 'php-ofc-library/open-flash-chart.php'; $max_y = 0; $arr_filled = array(); for ($i = 0; $i < count($dates); $i++) { $year[] = $dates[$i]; for ($m = 0; $m < count($vals); $m++) { $price[$m][] = (int) $vals[$m][$i]; if ($max_y < (int) $vals[$m][$i]) { $max_y = (int) $vals[$m][$i]; } if (@$arr_filled[$m] != $vals[$m][$i] and @$arr_filled[$m] == 0) { @($arr_filled[$m] = (int) $vals[$m][$i]); } } } while ($max_y % 10 != 0) { $max_y++; } $chart = new open_flash_chart(); //$title = new title( 'UK Petrol price (pence) per Litre' ); $d = new anchor(); if (count($dates) > 60) { $d->size(2); } else { $d->size(3); } $d->halo_size(1); $d->colour('#3D5C56'); $d->rotation(0); $d->sides(4); for ($i = 0; $i < count($price); $i++) { if ($arr_filled[$i] == 0) { continue; } if ($i == 0) { $color = '#5E0722'; } elseif ($i == 1) { $color = '#00FF00'; } else { $color = '#FF0000'; } $area = new area(); $area->set_colour($color); $area->set_default_dot_style($d); $area->set_values($price[$i]); if (isset($keys[$i])) { $area->set_key($keys[$i], 12); } // mb_convert_encoding($keys[$i], "UTF-8", "Windows-1251") $area->set_width(2); $chart->add_element($area); } $x_labels = new x_axis_labels(); if (count($dates) > 40) { $x_labels->set_steps(7); } else { $x_labels->set_steps(1); } $x_labels->set_vertical(); $x_labels->set_colour('#000000'); $x_labels->set_labels($year); $x_labels->rotate(-55); $x_labels->set_size(12); $x = new x_axis(); $x->set_colour('#000000'); $x->set_grid_colour('#DDDDDD'); //$x->set_offset( false ); $x->set_steps(1); // Add the X Axis Labels to the X Axis $x->set_labels($x_labels); $chart->set_x_axis($x); $y = new y_axis(); $y->set_range(0, $max_y); $y->set_colour('#000000'); $y->set_grid_colour('#DDDDDD'); $chart->add_y_axis($y); $chart->set_bg_colour("#FFFFFF"); ?> <script type="text/javascript" src="script/json/json2.js"></script> <script type="text/javascript" src="script/swfobject.js"></script> <script type="text/javascript"> swfobject.embedSWF("open-flash-chart.swf", "my_chart", "600", "350", "9.0.0"); </script> <script type="text/javascript"> function ofc_ready() { } function open_flash_chart_data() { return JSON.stringify(data); } function findSWF(movieName) { if (navigator.appName.indexOf("Microsoft")!= -1) { return window[movieName]; } else { return document[movieName]; } } var data = <?php echo $chart->toPrettyString(); ?> ; </script> <?php }